public ActionResult Add(Guid id) { try { var laborCategoryRates = new LaborCategoryRatesViewModel(); Guid categoryRateGuid = Guid.NewGuid(); var files = _contractRefactorService.GetFileByResourceGuid(id, Core.Entities.EnumGlobal.ResourceType.WorkBreakDownStructure.ToString()); if (files != null) { if (files.IsFile) { categoryRateGuid = files.ContentResourceGuid; } } laborCategoryRates.CategoryRateGuid = categoryRateGuid; laborCategoryRates.ContractGuid = id; return(PartialView(laborCategoryRates)); } catch (Exception ex) { ModelState.AddModelError(ex.ToString(), ex.Message); return(BadRequest(ModelState)); } }
public IActionResult Edit([FromForm] LaborCategoryRatesViewModel laborCategoryRates) { try { laborCategoryRates.UpdatedOn = CurrentDateTimeHelper.GetCurrentDateTime(); laborCategoryRates.UpdatedBy = UserHelper.CurrentUserGuid(HttpContext); laborCategoryRates.IsActive = true; laborCategoryRates.IsDeleted = false; if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var contractFile = ContractsMapper.MapSubcontractorBillingRatesViewModelToContractFiles(laborCategoryRates); _contractRefactorService.UpdateContractFile(contractFile); 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] LaborCategoryRatesViewModel laborCategoryRates) { try { if (laborCategoryRates.FileToUpload == null) { ModelState.AddModelError("", "Please insert the file."); return(BadRequest(ModelState)); } var isfileValid = _fileService.UploadFileTypeCheck(laborCategoryRates.FileToUpload); laborCategoryRates.CreatedOn = CurrentDateTimeHelper.GetCurrentDateTime(); laborCategoryRates.UpdatedOn = CurrentDateTimeHelper.GetCurrentDateTime(); laborCategoryRates.CreatedBy = UserHelper.CurrentUserGuid(HttpContext); laborCategoryRates.UpdatedBy = UserHelper.CurrentUserGuid(HttpContext); laborCategoryRates.IsActive = true; laborCategoryRates.IsDeleted = false; var contractNumber = _contractRefactorService.GetContractNumberById(laborCategoryRates.ContractGuid); var contractResourceFile = _contractResourceFileService.GetFilePathByResourceIdAndKeys(Core.Entities.EnumGlobal.ResourceType.LaborCategoryRates.ToString(), laborCategoryRates.ContractGuid); if (contractResourceFile != null && (laborCategoryRates.FileToUpload != null || laborCategoryRates.FileToUpload.Length != 0)) { var filename = ""; if (!isfileValid) { laborCategoryRates.IsCsv = false; filename = _fileService.FilePost($@"{documentRoot}/{contractResourceFile.FilePath}/", laborCategoryRates.FileToUpload); filePath = $"{contractResourceFile.FilePath}/{filename}"; } else { var file = _contractRefactorService.GetFileByResourceGuid(laborCategoryRates.ContractGuid, Core.Entities.EnumGlobal.ResourceType.LaborCategoryRates.ToString()); var previousFile = string.Empty; var relativePath = $@"{documentRoot}/{contractResourceFile.FilePath}/"; if (file != null) { previousFile = file.UploadFileName; } filename = _fileService.MoveFile(relativePath, previousFile, laborCategoryRates.FileToUpload); var fullPath = $@"{relativePath}/{filename}"; Helpers.CsvValidationHelper.ChecksValidHeaderAndReadTheFile(fullPath, relativePath, previousFile, (Models.ViewModels.EnumGlobal.UploadMethodName)UploadMethodName.SubcontractorLaborBillingRates); filePath = $"{contractResourceFile.FilePath}/{filename}"; laborCategoryRates.IsCsv = true; } laborCategoryRates.FilePath = filePath; laborCategoryRates.UploadFileName = filename; var contractFile = ContractsMapper.MapSubcontractorBillingRatesViewModelToContractFiles(laborCategoryRates); contractFile.ResourceType = Core.Entities.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(), "Labor Category Rates 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}", "Labor Category Rates", contractEntity.ContractNumber, contractEntity.ProjectNumber, laborCategoryRates.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}", "Labor Category Rates", contractEntity.ContractNumber, contractEntity.ProjectNumber, laborCategoryRates.UploadFileName); } AuditLogHandler.InfoLog(_logger, User.FindFirst("fullName").Value, UserHelper.CurrentUserGuid(HttpContext), contractFile, resource, contractFile.ContractResourceFileGuid, UserHelper.GetHostedIp(HttpContext), "File Uploaded", Guid.Empty, "Successful", "", additionalInformation, additionalInformationURl); //end of audit log. } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } return(Ok(new { status = ResponseStatus.success.ToString(), message = "Successfully Added !!" })); } catch (Exception ex) { ModelState.AddModelError(ex.ToString(), ex.Message); return(BadRequest(ModelState)); } }