public int UpsertProjectStructure(CMPCUpdateStructure request) { ResponseMessage response = new ResponseMessage(); response.Message = "Structure Updated successfully"; // if (request?.ProjectStructureDetail == null) // throw new ValueNotFoundException ("ProjectStructureDetail Request cannot be empty."); try { using (var transaction = _context.Database.BeginTransaction()) { try { var isUpdate = false; var projectStructureID = 0; var projectStructure = _context.ProjectStructure.Where(x => x.Id == request.ProjStructureId && x.IsDelete == false).FirstOrDefault(); projectStructure.DrawingNo = request.DrawingNo; projectStructure.UpdatedAt = DateTime.Now; projectStructure.EstimatedWeight = Convert.ToDecimal(request.EstimatedWeight); projectStructure.ComponentsCount = request.CompCount; _context.SaveChanges(); projectStructureID = projectStructure.Id; DispReqStructure dispStruct = _context.DispReqStructure.Where(x => x.Id == request.dispStructureId).FirstOrDefault(); dispStruct.DispStructStatus = Util.GetDescription(commonEnum.SiteDispStructureStatus.CMPCAPPROVED).ToString(); _context.SaveChanges(); int?dispReqId = dispStruct.DispreqId; DispatchRequirement dispReq = _context.DispatchRequirement.Where(x => x.Id == dispReqId).FirstOrDefault(); var lstDispStruct = _context.DispReqStructure.Where(x => x.DispreqId == dispReqId).ToList(); if (lstDispStruct.Count() == lstDispStruct.Where(x => x.DispStructStatus == Util.GetDescription(commonEnum.SiteDispStructureStatus.CMPCAPPROVED).ToString()).Count()) { dispReq.Status = Util.GetDescription(commonEnum.SiteDispatchSatus.CMPCAPPROVED).ToString(); dispReq.StatusInternal = Util.GetDescription(commonEnum.SiteDispatchSatus.CMPCAPPROVED).ToString(); } else { dispReq.Status = Util.GetDescription(commonEnum.SiteDispatchSatus.CMPCPARTIALLYAPPROVED).ToString(); dispReq.StatusInternal = Util.GetDescription(commonEnum.SiteDispatchSatus.CMPCPARTIALLYAPPROVED).ToString(); } _context.SaveChanges(); transaction.Commit(); return(projectStructureID); } catch (Exception ex) { transaction.Rollback(); throw ex; } } } catch (Exception ex) { throw ex; } }
public ResponseMessage UpsertAssignStructureComponent(CMPCUpdateStructure servicedto) { ResponseMessage response = new ResponseMessage(); response.Message = "structure updated succusfully"; int projStructId = _siteDispatchRepository.UpsertProjectStructure(servicedto); if (servicedto.uploadDocs != null) { foreach (IFormFile file in servicedto.uploadDocs) { Upload_Docs layerDoc = new Upload_Docs(); layerDoc.fileName = file.FileName; layerDoc.filepath = UploadedFile(file); layerDoc.uploadType = "Docs"; layerDoc.fileType = Path.GetExtension(file.FileName); this._assignRepo.StructureDocsUpload(layerDoc, projStructId); // _gridRepo.LayerDocsUpload(layerDoc, layerId); } } RemoveStructureDocs(servicedto.remove_docs_filename); return(response); }
public IActionResult AssignStructurecomponent([FromForm] CMPCUpdateStructure request) { try { if (request.uploadDocs != null) { if (request.uploadDocs.Length > 5) { throw new ValueNotFoundException("Document count should not greater than 5"); } foreach (IFormFile file in request.uploadDocs) { if (constantVal.AllowedDocFileTypes.Where(x => x.Contains(file.ContentType)).Count() == 0) { throw new ValueNotFoundException(string.Format("File Type {0} is not allowed", file.ContentType)); } } if (request.uploadDocs.Select(x => x.Length).Sum() > 50000000) { throw new ValueNotFoundException(" File size exceeded limit"); } } var projectStructure = _siteDispatchService.UpsertAssignStructureComponent(request); return(Ok(projectStructure)); } catch (ValueNotFoundException e) { Util.LogError(e); return(StatusCode(StatusCodes.Status422UnprocessableEntity, new ErrorClass() { code = StatusCodes.Status422UnprocessableEntity.ToString(), message = e.Message })); } catch (Exception e) { Util.LogError(e); return(StatusCode(StatusCodes.Status500InternalServerError, new ErrorClass() { code = StatusCodes.Status500InternalServerError.ToString(), message = "Something went wrong" })); } }