public async Task <UccountDto> UpdateUccount(long id, UccountDto dto) { var entity = await _uccountManager.Find(id); if (entity == null) { return(null); } var newEntity = _mapper.Map(dto, entity); entity = await _uccountManager.Update(newEntity); entity.Services = new List <UccountServiceEntity>(); foreach (var service in dto.Services) { var serviceEntity = await _uccountServiceManager.Find(id); if (serviceEntity == null) { continue; } var newServiceEntity = _mapper.Map(service, serviceEntity); entity.Services.Add(await _uccountServiceManager.Update(newServiceEntity)); } return(_mapper.Map <UccountDto>(entity)); }
public async Task <UccountDto> CreateUccount(UccountDto dto) { //var template = await _sectionManager.FindInclude(dto.TemplateId); //if(template != null) { //var sectionEntity = new UccountSectionEntity() { // Code = template.Code, // Name = template.Name, // Description = template.Description //}; //sectionEntity = await _uccountSectionManager.Create(sectionEntity); //var fieldsEntity = template.Fields.Select(x => new UccountSectionFieldEntity() { // Name = x.Name, // SectionId = sectionEntity.Id, // Type = x.Type, // Value = "" //}); //fieldsEntity = await _uccountSectionFieldManager.Create(fieldsEntity); //dto.SectionId = sectionEntity.Id; //dto.Services = await GetServices(dto.Id); foreach (var service in dto.Services) { await _uccountServiceManager.Create(new UccountServiceEntity { CategoryId = service.CategoryId, AccountId = service.UccountId }); } var entity = await _uccountManager.Create(_mapper.Map <UccountEntity>(dto)); return(_mapper.Map <UccountDto>(entity)); //} //return null; }