You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
152 lines
4.6 KiB
152 lines
4.6 KiB
using DbContextLib;
|
|
using Model.DTO;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Model.Mappers;
|
|
using Model.Business;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Entities.SQLudeoDB;
|
|
using ModelToEntity;
|
|
|
|
namespace Services
|
|
{
|
|
public class UserDataService : IUserDataService<UserDTO?>
|
|
{
|
|
private readonly IUserDataService<User> dataServiceEF;
|
|
public UserDataService(IUserDataService<User> dataServiceEF)
|
|
{
|
|
this.dataServiceEF = dataServiceEF;
|
|
}
|
|
|
|
public async Task<UserDTO?> GetUserById(int id)
|
|
{
|
|
var user = await dataServiceEF.GetUserById(id);
|
|
return user.FromModelToDTO();
|
|
}
|
|
|
|
public async Task<UserDTO?> GetUserByUsername(string username)
|
|
{
|
|
var user = await dataServiceEF.GetUserByUsername(username);
|
|
return user.FromModelToDTO();
|
|
}
|
|
|
|
public async Task<IEnumerable<UserDTO?>> GetUsers(int page, int number)
|
|
{
|
|
var users = await dataServiceEF.GetUsers(page, number);
|
|
return users.Select(u => u.FromModelToDTO());
|
|
}
|
|
|
|
public async Task<bool> DeleteUser(int id)
|
|
{
|
|
var respons = await dataServiceEF.DeleteUser(id);
|
|
return respons;
|
|
}
|
|
|
|
public async Task<UserDTO?> UpdateUser(int id, UserDTO user)
|
|
{
|
|
var updatingUser = await dataServiceEF.UpdateUser(id, user);
|
|
return updatingUser.FromModelToDTO();
|
|
}
|
|
public async Task<UserDTO?> CreateUser(string username, string password, string email, bool isAdmin)
|
|
{
|
|
var newUserEntity = await dataServiceEF.CreateUser(username, password, email, isAdmin);
|
|
return newUserEntity.FromModelToDTO();
|
|
}
|
|
|
|
public async Task<UserDTO?> AddItem(UserDTO? item)
|
|
{
|
|
var newItem = await dataServiceEF.AddItem(item.FromDTOToModel());
|
|
return newItem.FromModelToDTO();
|
|
}
|
|
|
|
public Task<bool> DeleteItem(int id)
|
|
{
|
|
var succes = dataServiceEF.DeleteItem(id);
|
|
return succes;
|
|
}
|
|
|
|
public async Task<UserDTO> UpdateItem<TDto>(int? id, TDto? newItem) where TDto : class
|
|
{
|
|
var item = await dataServiceEF.UpdateItem<TDto>(id, newItem);
|
|
return item.FromModelToDTO();
|
|
}
|
|
|
|
public async Task<IEnumerable<UserDTO?>> GetItems(int index, int count, string? orderingPropertyName = null, object? valueProperty = null)
|
|
{
|
|
try
|
|
{
|
|
var items = await dataServiceEF.GetItems(index, count, orderingPropertyName, valueProperty);
|
|
return items.Select(item => item.FromModelToDTO());
|
|
}
|
|
catch (KeyNotFoundException ex)
|
|
{
|
|
throw;
|
|
}
|
|
|
|
}
|
|
|
|
public Task<IEnumerable<ParagraphDTO>> GetParagraphs(int page, int number)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public Task<ParagraphDTO> GetParagraphById(int id)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public Task<ParagraphDTO> GetParagraphByTitle(string title)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public Task<bool> DeleteParagraph(int id)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public Task<ParagraphDTO> UpdateParagraph(int id, ParagraphDTO paragraphDTO)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public Task<ParagraphDTO> CreateParagraph(string title, string content, string info, string query, string comment)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public Task<IEnumerable<UserDTO>> GetSuccesses(int page, int number)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public Task<UserDTO> GetSuccessByUserId(int id)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public Task<UserDTO> GetSuccessByInquiryId(int id)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public Task<bool> DeleteSuccess(int id)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public Task<UserDTO> UpdateSuccess(int id, SuccessDTO success)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public Task<UserDTO> CreateSuccess(int userId, int inquiryId, bool isFinished)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
}
|