protected virtual async Task Update(CreateOrEditProjectDto input) { var project = await _projectRepository.FirstOrDefaultAsync((int)input.Id); project.Locations = _projectLocationRepository.GetAll().Where(x => x.ProjectId == project.Id).ToList(); var oldProjectLocations = new HashSet <ProjectLocation>(project.Locations.ToList()); var newProjectLocations = new HashSet <ProjectLocationDto>(input.Locations.ToList()); foreach (var detail in oldProjectLocations) { if (!newProjectLocations.Any(x => x.Id == detail.Id)) { project.Locations.Remove(detail); } else { var inputDetail = newProjectLocations.Where(x => x.Id == detail.Id).FirstOrDefault(); } } foreach (var item in newProjectLocations) { if (item.Id == 0) { project.Locations.Add(ObjectMapper.Map <ProjectLocation>(item)); } } await _projectRepository.UpdateAsync(project); }
protected virtual async Task Create(CreateOrEditProjectDto input) { var project = ObjectMapper.Map <Project>(input); await _projectRepository.InsertAsync(project); }
public async Task CreateOrEdit(CreateOrEditProjectDto input) { if (input.Id == null) { await Create(input); } else { await Update(input); } }
protected virtual async Task Create(CreateOrEditProjectDto input) { var project = ObjectMapper.Map <Project>(input); if (AbpSession.TenantId != null) { project.TenantId = (int?)AbpSession.TenantId; } await _projectRepository.InsertAsync(project); }
protected virtual async Task Create(CreateOrEditProjectDto input) { var project = ObjectMapper.Map <Project>(input); project.Locations = new List <ProjectLocation>(); if (input.Locations.Count > 0) { foreach (var item in input.Locations) { project.Locations.Add(ObjectMapper.Map <ProjectLocation>(item)); } } await _projectRepository.InsertAsync(project); }
protected virtual async Task Update(CreateOrEditProjectDto input) { var project = await _projectRepository.FirstOrDefaultAsync((int)input.Id); ObjectMapper.Map(input, project); }