2023-11-16 20:39:00 +04:00
|
|
|
|
using AccountsContracts.BindingModels;
|
|
|
|
|
using AccountsContracts.ViewModels;
|
|
|
|
|
using AccountsDataModels.Models;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace AccountsDataBaseImplement.Models
|
|
|
|
|
{
|
|
|
|
|
public class Account : IAccountModel
|
|
|
|
|
{
|
|
|
|
|
[Required]
|
|
|
|
|
public string Login { get; set; } = string.Empty;
|
|
|
|
|
[Required]
|
|
|
|
|
public string Password { get; set; } = string.Empty;
|
|
|
|
|
[Required]
|
|
|
|
|
public string Email { get; set; } = string.Empty;
|
|
|
|
|
|
|
|
|
|
public int Id { get; private set; }
|
|
|
|
|
|
2023-11-29 23:40:28 +04:00
|
|
|
|
public int InterestId { get; set; }
|
|
|
|
|
|
|
|
|
|
public virtual Interest Interest { get; set; } = new();
|
2023-11-16 20:39:00 +04:00
|
|
|
|
|
2023-11-29 23:40:28 +04:00
|
|
|
|
public static Account? Create(AccountsDatabase context, AccountBindingModel? model)
|
2023-11-16 20:39:00 +04:00
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return new Account()
|
|
|
|
|
{
|
|
|
|
|
Id = model.Id,
|
|
|
|
|
Login = model.Login,
|
|
|
|
|
Password = model.Password,
|
|
|
|
|
Email = model.Email,
|
2023-11-29 23:40:28 +04:00
|
|
|
|
InterestId = model.InterestId,
|
|
|
|
|
Interest = context.Interests.First(x => x.Id == model.InterestId),
|
2023-11-16 20:39:00 +04:00
|
|
|
|
};
|
|
|
|
|
}
|
2023-11-29 23:40:28 +04:00
|
|
|
|
|
|
|
|
|
public void Update(AccountBindingModel? model, AccountsDatabase context)
|
2023-11-16 20:39:00 +04:00
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Login = model.Login;
|
|
|
|
|
Password = model.Password;
|
2023-11-29 23:40:28 +04:00
|
|
|
|
InterestId = model.InterestId;
|
|
|
|
|
Interest = context.Interests.First(x => x.Id == model.InterestId);
|
2023-11-16 20:39:00 +04:00
|
|
|
|
}
|
2023-11-29 23:40:28 +04:00
|
|
|
|
|
2023-11-16 20:39:00 +04:00
|
|
|
|
public AccountViewModel GetViewModel => new()
|
|
|
|
|
{
|
|
|
|
|
Id = Id,
|
|
|
|
|
Login = Login,
|
|
|
|
|
Password = Password,
|
|
|
|
|
Email = Email,
|
2023-11-29 23:40:28 +04:00
|
|
|
|
InterestId = InterestId,
|
|
|
|
|
InterestName = Interest.Name,
|
2023-11-16 20:39:00 +04:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|