public IActionResult Edit([FromForm] EmployeeBillingRatesViewModel employeeBillingRates) { try { employeeBillingRates.UpdatedOn = CurrentDateTimeHelper.GetCurrentDateTime(); employeeBillingRates.UpdatedBy = UserHelper.CurrentUserGuid(HttpContext); employeeBillingRates.IsActive = true; employeeBillingRates.IsDeleted = false; if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //var employeeBillingRatesEntity = _mapper.Map<EmployeeBillingRates>(employeeBillingRates); //_employeeBillingRatesService.UpdateEmployeeBillingRates(employeeBillingRatesEntity); //later added var file = ContractsMapper.MapEmployeeBillingRatesViewModelToContractFiles(employeeBillingRates); _contractRefactorService.UpdateContractFile(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] EmployeeBillingRatesViewModel employeeBillingRates) { try { if (employeeBillingRates.FileToUpload == null) { ModelState.AddModelError("", "Please insert the file."); return(BadRequest(ModelState)); } var isfileValid = _fileService.UploadFileTypeCheck(employeeBillingRates.FileToUpload); employeeBillingRates.CreatedOn = CurrentDateTimeHelper.GetCurrentDateTime(); employeeBillingRates.UpdatedOn = CurrentDateTimeHelper.GetCurrentDateTime(); employeeBillingRates.CreatedBy = UserHelper.CurrentUserGuid(HttpContext); employeeBillingRates.UpdatedBy = UserHelper.CurrentUserGuid(HttpContext); employeeBillingRates.IsActive = true; employeeBillingRates.IsDeleted = false; var contractNumber = _contractRefactorService.GetContractNumberById(employeeBillingRates.ContractGuid); var contractResourceFile = _contractResourceFileService.GetFilePathByResourceIdAndKeys(Core.Entities.EnumGlobal.ResourceType.EmployeeBillingRates.ToString(), employeeBillingRates.ContractGuid); if (contractResourceFile != null && (employeeBillingRates.FileToUpload != null || employeeBillingRates.FileToUpload.Length != 0)) { var filename = ""; if (!isfileValid) { var directoryPath = Path.GetDirectoryName(contractResourceFile.FilePath); filename = _fileService.FilePost($@"{documentRoot}/{contractResourceFile.FilePath}/", employeeBillingRates.FileToUpload); employeeBillingRates.IsCsv = false; filePath = $"{contractResourceFile.FilePath}/{filename}"; } else { var files = _contractRefactorService.GetFileByResourceGuid(employeeBillingRates.ContractGuid, Core.Entities.EnumGlobal.ResourceType.EmployeeBillingRates.ToString()); var relativePath = $@"{documentRoot}/{contractResourceFile.FilePath}/"; var previousFile = string.Empty; if (files != null) { previousFile = files.UploadFileName; } filename = _fileService.MoveFile(relativePath, previousFile, employeeBillingRates.FileToUpload); employeeBillingRates.IsCsv = true; var fullPath = $@"{relativePath}/{filename}"; Helpers.CsvValidationHelper.ChecksValidHeaderAndReadTheFile(fullPath, relativePath, previousFile, (Models.ViewModels.EnumGlobal.UploadMethodName)UploadMethodName.EmployeeBillingRate); filePath = $"{contractResourceFile.FilePath}/{filename}"; } employeeBillingRates.FilePath = filePath; employeeBillingRates.UploadFileName = filename; } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var contractFile = ContractsMapper.MapEmployeeBillingRatesViewModelToContractFiles(employeeBillingRates); 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(), "Employee Billing 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}", "Employee Billing Rates", contractEntity.ContractNumber, contractEntity.ProjectNumber, employeeBillingRates.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}", "Employee Billing Rates", contractEntity.ContractNumber, contractEntity.ProjectNumber, employeeBillingRates.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. return(Ok(new { status = ResponseStatus.success.ToString(), message = "Successfully Added !!" })); } catch (Exception ex) { ModelState.AddModelError(ex.ToString(), ex.Message); return(BadRequest(ModelState)); } }