public IActionResult Edit([FromForm] ContractWBSViewModel contractWBS) { try { contractWBS.UpdatedOn = CurrentDateTimeHelper.GetCurrentDateTime(); contractWBS.UpdatedBy = UserHelper.CurrentUserGuid(HttpContext); contractWBS.IsActive = true; contractWBS.IsDeleted = false; if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //var wbsEntity = _mapper.Map<ContractWBS>(contractWBS); //_contractWBSService.UpdateContractWBS(wbsEntity); //add file to contract file var contractFile = ContractsMapper.MapContractWBSViewModelToContractResourceFile(contractWBS); _contractRefactorService.UpdateContractFile(contractFile); //end of contract file return(Ok(new { status = ResponseStatus.success.ToString(), message = "Successfully Edited !!" })); } catch (Exception ex) { ModelState.AddModelError(ex.ToString(), ex.Message); return(BadRequest(ModelState)); } }
public IActionResult Add([FromForm] ContractWBSViewModel contractWBS) { try { if (contractWBS.FileToUpload == null) { ModelState.AddModelError("", "Please insert the file."); return(BadRequest(ModelState)); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } contractWBS.CreatedOn = CurrentDateTimeHelper.GetCurrentDateTime(); contractWBS.UpdatedOn = CurrentDateTimeHelper.GetCurrentDateTime(); contractWBS.CreatedBy = UserHelper.CurrentUserGuid(HttpContext); contractWBS.UpdatedBy = UserHelper.CurrentUserGuid(HttpContext); contractWBS.IsActive = true; contractWBS.IsDeleted = false; contractWBS.IsCsv = true; string filePath = string.Empty; // gets the contractnumber to save the file in the folder. var contractNumber = _contractRefactorService.GetContractNumberById(contractWBS.ContractGuid); var contractResourceFile = _contractResourceFileService.GetFilePathByResourceIdAndKeys(EnumGlobal.ResourceType.WorkBreakDownStructure.ToString(), contractWBS.ContractGuid); if (contractWBS.FileToUpload != null || contractWBS.FileToUpload.Length != 0) { var filename = ""; //checks whether the file extension is the correct one and the validates the fields if the file is Csv. var isfileValid = _fileService.UploadFileTypeCheck(contractWBS.FileToUpload); if (!isfileValid) { filename = _fileService.FilePost($@"{documentRoot}/{contractResourceFile.FilePath}/", contractWBS.FileToUpload); contractWBS.IsCsv = false; filePath = $"{contractResourceFile.FilePath}/{filename}"; } else { var files = _contractRefactorService.GetFileByResourceGuid(contractWBS.ContractGuid, Core.Entities.EnumGlobal.ResourceType.WorkBreakDownStructure.ToString()); var previousFile = string.Empty; var relativePath = $@"{documentRoot}/{contractResourceFile.FilePath}/"; if (files != null) { previousFile = files.UploadFileName; } filename = _fileService.MoveFile(relativePath, previousFile, contractWBS.FileToUpload); var fullPath = $@"{relativePath}/{filename}"; CsvValidationHelper.ChecksValidHeaderAndReadTheFile(fullPath, relativePath, previousFile, (Models.ViewModels.EnumGlobal.UploadMethodName)UploadMethodName.WorkBreakDownStructure); filePath = $"{contractResourceFile.FilePath}/{filename}"; contractWBS.IsCsv = true; } contractWBS.FilePath = filePath; contractWBS.UploadFileName = filename; var contractFile = ContractsMapper.MapContractWBSViewModelToContractResourceFile(contractWBS); contractFile.ResourceType = EnumGlobal.ResourceType.Contract.ToString(); if (contractResourceFile != null) { contractFile.ParentId = contractResourceFile.ContractResourceFileGuid; } _contractRefactorService.CheckAndInsertContractFile(contractFile); //audit log.. var contractEntity = _contractRefactorService.GetContractEntityByContractId(contractFile.ResourceGuid); var additionalInformation = string.Format("{0} {1} the {2}", User.FindFirst("fullName").Value, CrudTypeForAdditionalLogMessage.Uploaded.ToString(), "Work BreakDown Structure File"); string additionalInformationURl = string.Empty; string resource = string.Empty; if (contractEntity.ParentContractGuid == Guid.Empty || contractEntity.ParentContractGuid == null) { additionalInformationURl = _configuration.GetSection("SiteUrl").Value + ("/Contract/Details/" + contractEntity.ContractGuid); resource = string.Format("{0} </br> Contract No:{1} </br> Project No:{2} </br> File Name:{3}", "Work BreakDown Structure", contractEntity.ContractNumber, contractEntity.ProjectNumber, contractWBS.UploadFileName); } else { additionalInformationURl = _configuration.GetSection("SiteUrl").Value + ("/Project/Details/" + contractEntity.ContractGuid); resource = string.Format("{0} </br> TaskOrder No:{1} </br> Project No:{2} </br> File Name:{3}", "Work BreakDown Structure", contractEntity.ContractNumber, contractEntity.ProjectNumber, contractWBS.UploadFileName); } AuditLogHandler.InfoLog(_logger, User.FindFirst("fullName").Value, UserHelper.CurrentUserGuid(HttpContext), contractFile, resource, contractFile.ContractResourceFileGuid, UserHelper.GetHostedIp(HttpContext), "File Uploaded", Guid.Empty, "Successful", "", additionalInformationURl, additionalInformationURl); //end of audit log. } //add file to contract file return(Ok(new { status = ResponseStatus.success.ToString(), message = "Successfully Added !!" })); } catch (Exception ex) { ModelState.AddModelError(ex.ToString(), ex.Message); return(BadRequest(ModelState)); } }