first commit
This commit is contained in:
92
Complex.Application/Services/PersonService/PersonService.cs
Normal file
92
Complex.Application/Services/PersonService/PersonService.cs
Normal file
@@ -0,0 +1,92 @@
|
||||
using AutoMapper;
|
||||
using Complex.Application.Utility;
|
||||
using Complex.Common.Dto;
|
||||
using Complex.Domain.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Complex.Application.PersonService
|
||||
{
|
||||
public interface IPersonService
|
||||
{
|
||||
public ResultDto<string> InsertPerson(PersonDto person);
|
||||
public ResultDto<bool> EditPerson(PersonDto person);
|
||||
public ResultDto<List<PersonDto>> GetAllPersons(PersonDto personSearchObj);
|
||||
}
|
||||
public class PersonService : IPersonService
|
||||
{
|
||||
private readonly IComplexDBContext _complexDBContext;
|
||||
private IMapper _mapper;
|
||||
public PersonService(IComplexDBContext complexDBContext, IMapper mapper)
|
||||
{
|
||||
_complexDBContext = complexDBContext;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
public ResultDto<List<PersonDto>> GetAllPersons(PersonDto personSearchObj)
|
||||
{
|
||||
var persons = _complexDBContext.ComplexPersons.Where(u => u.ComplexId == personSearchObj.ComplexId).Select(cp => cp.PersonMobileNumber);
|
||||
//در تمام فیلدها با شماره تلفن میتوان جستجو کرد
|
||||
if (personSearchObj.MobileNumber.IsNotNullOrEmpty())
|
||||
{
|
||||
persons = persons.Where(p => p.Id.Contains(personSearchObj.MobileNumber));
|
||||
persons = persons.Where(p => p.FirstName.Contains(personSearchObj.MobileNumber));
|
||||
persons = persons.Where(p => p.FirstName.Contains(personSearchObj.MobileNumber));
|
||||
}
|
||||
//if (personSearchObj.FirstName.IsNotNullOrEmpty())
|
||||
// persons = persons.Where(p => p.FirstName.Contains(personSearchObj.FirstName));
|
||||
|
||||
//if (personSearchObj.LastName.IsNotNullOrEmpty())
|
||||
// persons = persons.Where(p => p.LastName.Contains(personSearchObj.LastName));
|
||||
|
||||
//var persons = _complexDBContext.Units.Where(u => u.ComplexId == personSearchObj.ComplexId).Select(p => p.Tenant);
|
||||
//persons = persons.Union(_complexDBContext.Units.Where(u => u.ComplexId == personSearchObj.ComplexId).Select(p => p.Owner));
|
||||
|
||||
//if (personSearchObj.MobileNumber.IsNotNullOrEmpty())
|
||||
// persons = persons.Where(p => p.Id.Contains(personSearchObj.MobileNumber));
|
||||
|
||||
//var personResult = persons.Distinct().ToList();
|
||||
return new ResultDto<List<PersonDto>>
|
||||
{
|
||||
Data = persons.Select(p => _mapper.Map<PersonDto>(p)).ToList(),
|
||||
IsSuccess = true
|
||||
};
|
||||
}
|
||||
|
||||
public ResultDto<bool> EditPerson(PersonDto person)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public ResultDto<string> InsertPerson(PersonDto personDto)
|
||||
{
|
||||
var newPerson = _mapper.Map<Person>(personDto);
|
||||
var isExist = _complexDBContext.Persons.Any(p => p.Id == personDto.MobileNumber);
|
||||
if (!isExist)
|
||||
{
|
||||
newPerson.Id = personDto.MobileNumber;
|
||||
_complexDBContext.Persons.Add(newPerson);
|
||||
_complexDBContext.SaveChanges();
|
||||
}
|
||||
_complexDBContext.ComplexPersons.Add(new ComplexPerson
|
||||
{
|
||||
ComplexId = personDto.ComplexId.Value,
|
||||
PersonMobileNumberId = personDto.MobileNumber,
|
||||
});
|
||||
return new ResultDto<string> { Data = newPerson.Id, IsSuccess = true };
|
||||
}
|
||||
}
|
||||
public class PersonDto
|
||||
{
|
||||
public Guid? ComplexId { set; get; }
|
||||
public string? MobileNumber { set; get; }
|
||||
public string? FirstName { get; set; }
|
||||
public string? LastName { get; set; }
|
||||
public byte? Gender { set; get; }
|
||||
//public int? MobileCode { set; get; }
|
||||
public byte[]? Avatar { set; get; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user