Exemplo n.º 1
0
        public IActionResult Get([FromBody] string searchText)
        {
            try
            {
                var list = JsonConvert.DeserializeObject <List <GridHeaderModel> >(searchText);
                if (list.Count == 0)
                {
                    return(BadRequest(new { status = ResponseStatus.error.ToString(), path = " : No Any Data In The Row" }));
                }
                string filePath             = string.Empty;
                var    contractGuid         = list[0].ContractGuid;
                var    model                = _contractRefactorService.GetFileByResourceGuid(contractGuid, Core.Entities.EnumGlobal.ResourceType.WorkBreakDownStructure.ToString());
                var    contractResourceFile = _contractResourceFileService.GetFilePathByResourceIdAndKeys(Core.Entities.EnumGlobal.ResourceType.WorkBreakDownStructure.ToString(), contractGuid);
                string fileName             = string.Format(model.UploadFileName, System.AppContext.BaseDirectory);
                var    listdata             = list.Select(x => new
                {
                    WBSCode            = x.WBSCode,
                    Description        = x.Description,
                    Value              = x.Value,
                    ContractType       = x.ContractType,
                    InvoiceAtThisLevel = x.InvoiceAtThisLevel
                }).ToList();
                var dynamicList = listdata.Cast <dynamic>().ToList();

                // saves the files to the folder specified
                var relativePath = $@"{documentRoot}/{contractResourceFile.FilePath}/";
                var fullPath     = $@"{relativePath }/{fileName}";
                CsvValidationHelper.MoveFile(relativePath, fileName);
                CsvValidationHelper.SaveTheUpdatedCsv(dynamicList, fullPath);
                var previousFile = string.Empty;
                if (model != null)
                {
                    previousFile = model.UploadFileName;
                }
                // after file save the saved file is valid if not valid the file is deleted
                CsvValidationHelper.ChecksValidHeaderAndReadTheFile(fullPath, relativePath, previousFile, (Models.ViewModels.EnumGlobal.UploadMethodName)UploadMethodName.WorkBreakDownStructure);

                //updates the new filename/path to the database
                model.FilePath       = contractResourceFile.FilePath + "/" + fileName;
                model.UploadFileName = fileName;
                model.IsCsv          = true;
                model.IsFile         = true;
                _contractRefactorService.CheckAndInsertContractFile(model);

                return(Ok(new { status = ResponseStatus.success.ToString(), id = model.ContractResourceFileGuid }));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Exemplo n.º 2
0
        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));
            }
        }