public ValueDataResponse <Project> UpdateProject(UpsertProject project) { ValueDataResponse <Project> response = new ValueDataResponse <Project>(); try { var projectsExists = _appContext.Projects.Where(x => x.Id != project.Id && x.ProjectReference == project.ProjectReference).FirstOrDefault(); if (projectsExists == null) { Project pro = _mapper.Map <Project>(project); var result = _appContext.Projects.Where(x => x.Id == project.Id).FirstOrDefault(); var projectList = _appContext.LookUpProjectXrefs.Where(x => x.ProjectId == project.Id).ToList(); _appContext.LookUpProjectXrefs.RemoveRange(projectList); _appContext.SaveChanges(); foreach (var sId in project.StoreIds) { _appContext.LookUpProjectXrefs.Add(new LookUpProjectXref { StoreId = sId, ProjectId = pro.Id }); } if (result != null) { result.SiteId = project.SiteId; result.ProjectReference = project.ProjectReference; result.Name1 = project.Name1; result.Name2 = project.Name2; result.ProjectDetails = project.ProjectDetails; result.IsActive = project.IsActive; result.CreatedBy = project.CreatedBy; result.CreatedDate = project.CreatedDate; result.UpdatedBy = project.UpdatedBy; result.UpdatedDate = project.UpdatedDate; foreach (var req in project.ProjectRepositories) { if (req.FileName != null) { string ModuleName = "Project"; var now = DateTime.Now; var yearName = now.ToString("yyyy"); var monthName = now.Month.ToString("d2"); var dayName = now.ToString("dd"); FileUploadService repo = new FileUploadService(); string FolderLocation = "FileRepository"; string ServerRootPath = _config.Value.ServerRootPath; string Location = ServerRootPath + @"\" + FolderLocation + @"\" + yearName + @"\" + monthName + @"\" + dayName + @"\" + ModuleName; byte[] FileBytes = Convert.FromBase64String(req.FileName); req.FileName = repo.UploadFile(FileBytes, req.FileExtention, Location); req.FileLocation = Path.Combine(yearName, monthName, dayName, ModuleName); ProjectRepository pros = new ProjectRepository(); { pros.ProjectId = pro.Id; pros.FileName = req.FileName; pros.FileLocation = req.FileLocation; pros.FileExtention = req.FileExtention; pros.DocumentType = req.DocumentTypeId; pros.CreatedBy = req.CreatedBy; pros.CreatedDate = DateTime.Now; pros.UpdatedBy = req.UpdatedBy; pros.UpdatedDate = DateTime.Now; } _appContext.ProjectRepositories.Add(pros); } } _appContext.SaveChanges(); if (pro != null) { response.Result = pro; response.IsSuccess = true; response.AffectedRecords = 1; response.EndUserMessage = "Project Updated Successfully"; } else { response.IsSuccess = true; response.AffectedRecords = 0; response.EndUserMessage = "Project Update Failed"; } } } else { response.IsSuccess = false; response.AffectedRecords = 0; response.EndUserMessage = "Project Reference is Already Exists"; } } catch (Exception ex) { response.IsSuccess = false; response.AffectedRecords = 0; response.EndUserMessage = ex.InnerException == null ? ex.Message : ex.InnerException.Message; response.Exception = ex; } return(response); }
public ValueDataResponse <Project> Update(UpsertProject project) { // Project pro = _mapper.Map<Project>(project); return(_unitOfWork.Projects.UpdateProject(project)); }