//Import attachment file
        private void ImportContractAttachment(List <string> fileList, string resurceType, Guid contractGuid, Guid resourceGuid, bool isDelete)
        {
            var destinationPath = string.Empty;

            foreach (var item in fileList)
            {
                var folder = _documentManagementService.GetFolderByKey("Contract", contractGuid, resurceType);
                var contractResourceFile = _contractResourceFileService.GetFilePathByResourceIdAndKeys(resurceType, contractGuid);
                if (contractResourceFile != null)
                {
                    destinationPath = rootPath + contractResourceFile.FilePath + "/";
                    var fileSize   = new System.IO.FileInfo(item).Length.ToString();
                    var outPutPath = _importFileService.MoveAttachment(item, destinationPath, isDelete);
                    if (!string.IsNullOrWhiteSpace(outPutPath))
                    {
                        var isCSV = Path.GetExtension(item) == ".csv" ? true : false;
                        ContractResourceFile contractFile = new ContractResourceFile();
                        contractFile.ContractResourceFileGuid = Guid.NewGuid();
                        contractFile.ResourceGuid             = contractGuid;
                        contractFile.CreatedBy           = loggedUser;
                        contractFile.CreatedOn           = DateTime.UtcNow;
                        contractFile.Keys                = resurceType;
                        contractFile.IsActive            = true;
                        contractFile.IsCsv               = isCSV;
                        contractFile.IsDeleted           = false;
                        contractFile.UpdatedBy           = loggedUser;
                        contractFile.UpdatedOn           = DateTime.Now;
                        contractFile.ContentResourceGuid = resourceGuid;
                        contractFile.IsFile              = true;
                        contractFile.ResourceType        = "Contract";
                        contractFile.UploadFileName      = Path.GetFileName(item);
                        contractFile.FilePath            = outPutPath.Replace(rootPath, "");
                        contractFile.FileSize            = fileSize;
                        if (folder != null)
                        {
                            contractFile.ParentId = contractResourceFile.ContractResourceFileGuid;
                        }
                        _contractsService.InsertContractFile(contractFile);
                    }
                }
            }
        }
Пример #2
0
        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));
            }
        }
        public IActionResult Add([FromBody] ContractModificationViewModel contractModificationModel)
        {
            try
            {
                List <string> filePath = new List <string>();


                string validation = validateModel(contractModificationModel);
                if (validation != YesNoStatus.Yes.ToString())
                {
                    ModelState.AddModelError("", validation);
                    return(BadRequest(ModelState));
                }

                if (ModelState.IsValid)
                {
                    Guid id = Guid.NewGuid();
                    contractModificationModel.ContractModificationGuid = id;
                    contractModificationModel.CreatedOn   = CurrentDateTimeHelper.GetCurrentDateTime();
                    contractModificationModel.CreatedBy   = UserHelper.CurrentUserGuid(HttpContext);
                    contractModificationModel.UpdatedOn   = CurrentDateTimeHelper.GetCurrentDateTime();
                    contractModificationModel.UpdatedBy   = UserHelper.CurrentUserGuid(HttpContext);
                    contractModificationModel.IsActive    = true;
                    contractModificationModel.IsDeleted   = false;
                    contractModificationModel.AwardAmount = contractModificationModel.AwardAmount ?? 0;

                    if (!ModelState.IsValid)
                    {
                        return(BadRequest(ModelState));
                    }
                    var contractId              = _contractService.GetContractIdByProjectId(contractModificationModel.ContractGuid);
                    var parentContractNumber    = _contractService.GetContractNumberById(contractId);
                    var taskOrderContractNumber = _contractService.GetContractNumberById(contractModificationModel.ContractGuid);
                    var taskModificationEntity  = _mapper.Map <ContractModification>(contractModificationModel);
                    taskModificationEntity.IsTaskModification = true;

                    //added task modification through contract modification
                    _contractModificationService.Add(taskModificationEntity);

                    //audit log..
                    var additionalInformation    = string.Format("{0} {1} the {2}", User.FindFirst("fullName").Value, CrudTypeForAdditionalLogMessage.Added.ToString(), "Task Order Mod");
                    var additionalInformationURl = _configuration.GetSection("SiteUrl").Value + ("/Project/Details/" + taskModificationEntity.ContractGuid);
                    var resource = string.Format("{0} </br> Mod No:{1} </br> Mod Title:{2}", "Task Order Mod", taskModificationEntity.ModificationNumber, taskModificationEntity.ModificationTitle);
                    AuditLogHandler.InfoLog(_logger, User.FindFirst("fullName").Value, UserHelper.CurrentUserGuid(HttpContext), taskModificationEntity, resource, taskModificationEntity.ContractModificationGuid, UserHelper.GetHostedIp(HttpContext), "Taskorder Mod Added", Guid.Empty, "Successful", "", additionalInformationURl, additionalInformationURl);
                    //end of log..

                    bool istriggered = false;
                    var  revenueGuid = SaveAndNotifyRevenueRepresentative(taskModificationEntity);
                    if (revenueGuid != Guid.Empty)
                    {
                        istriggered = true;
                    }

                    bool isViewHistory = false;

                    var historyCount = _revenueRecognitionService.DetailListCount(taskModificationEntity.ContractGuid, "");
                    if (historyCount > 0)
                    {
                        isViewHistory = true;
                    }

                    //get file info..
                    var contractResourceFile = _contractResourceFileService.GetFilePathByResourceIdAndKeys(ContractResourceFileKey.ContractModification.ToString(), contractModificationModel.ContractGuid);

                    var jsonObject = new
                    {
                        status       = ResponseStatus.success.ToString(),
                        message      = "Successfully Added !!",
                        revenueGuid  = revenueGuid,
                        viewHistory  = isViewHistory,
                        istriggered  = istriggered,
                        contractGuid = taskModificationEntity.ContractGuid,
                        resourceId   = taskModificationEntity.ContractModificationGuid,
                        uploadPath   = contractResourceFile.FilePath,
                        parentId     = contractResourceFile.ContractResourceFileGuid
                    };

                    return(Ok(jsonObject));
                }
                else
                {
                    return(BadRequest(ModelState));
                }
            }
            catch (ArgumentException ex)
            {
                ModelState.AddModelError("", ex.Message);
                return(BadRequestFormatter.BadRequest(this, ex));
            }
            catch (Exception e)
            {
                ModelState.AddModelError("", e.Message);
                return(BadRequestFormatter.BadRequest(this, e));
            }
        }
        public IActionResult UploadSaveFile(Guid resourceId, string resourceKey, string uploadPath, string[] fileInfo, Guid parentid, string contractResourceFileKey, Guid ContentResourceGuid)
        {
            try
            {
                //Avoiding Kendo Uploader's default call
                if (resourceId == Guid.Empty || string.IsNullOrEmpty(uploadPath))
                {
                    return(Ok(true));
                }

                //If new file/s have been uploaded
                if (Request.Form.Files.Count > 0)
                {
                    var files = Request.Form.Files;
                    //foreach (var file in files)
                    for (int i = 0; i < files.Count; i++)
                    {
                        var fileInfoObj = fileInfo[i].Split(',');

                        //save file in folder..

                        var fullPath         = files[i].FileName.Split("\\");
                        var originalFileName = fullPath[fullPath.Length - 1];

                        //var fullPhysicalFilePath = Path.Combine(documentRoot, uploadPath);
                        var fullPhysicalFilePath = string.Concat(documentRoot, uploadPath);

                        var uniqueFileName =
                            _fileService.SaveFile(fullPhysicalFilePath, files[i]);

                        var relativeFilePath = Path.Combine(uploadPath, uniqueFileName);

                        //save file info in database..
                        ContractFileViewModel contractFileViewModel = new ContractFileViewModel();

                        contractFileViewModel.ContractResourceFileGuid = new Guid(fileInfoObj[0]);
                        contractFileViewModel.CreatedOn    = CurrentDateTimeHelper.GetCurrentDateTime();
                        contractFileViewModel.UpdatedOn    = CurrentDateTimeHelper.GetCurrentDateTime();
                        contractFileViewModel.CreatedBy    = UserHelper.CurrentUserGuid(HttpContext);
                        contractFileViewModel.UpdatedBy    = UserHelper.CurrentUserGuid(HttpContext);
                        contractFileViewModel.Description  = WebUtility.UrlDecode(fileInfoObj[1]);
                        contractFileViewModel.MimeType     = files[i].ContentType;
                        contractFileViewModel.ResourceGuid = resourceId;
                        //contractFileViewModel.keys = resourceKey;
                        contractFileViewModel.ParentId             = parentid;
                        contractFileViewModel.UploadFileName       = uniqueFileName;
                        contractFileViewModel.UploadUniqueFileName = uniqueFileName;
                        contractFileViewModel.IsActive             = true;
                        contractFileViewModel.IsDeleted            = false;
                        contractFileViewModel.FilePath             = relativeFilePath;
                        contractFileViewModel.FileSize             = fileInfoObj[4];
                        contractFileViewModel.Isfile              = true;
                        contractFileViewModel.keys                = contractResourceFileKey;
                        contractFileViewModel.ResourceType        = resourceKey;
                        contractFileViewModel.ContentResourceGuid = ContentResourceGuid;

                        if (resourceKey.ToUpper() == EnumGlobal.ResourceType.ContractModification.ToString().ToUpper() || resourceKey.ToUpper() == EnumGlobal.ResourceType.TaskOrderModification.ToString().ToUpper())
                        {
                            var contractGuid         = _contractModificationService.GetDetailById(ContentResourceGuid).ContractGuid;
                            var contractResourceFile = _contractResourceFileService.GetFilePathByResourceIdAndKeys(ContractResourceFileKey.ContractModification.ToString(), contractGuid);
                            contractFileViewModel.ParentId     = contractResourceFile.ContractResourceFileGuid;
                            contractFileViewModel.keys         = ContractResourceFileKey.ContractModification.ToString();
                            contractFileViewModel.ResourceGuid = contractGuid;

                            //contractFileViewModel.ResourceType = resourceKey;
                            //for task order also resourcetype is Contract to show in the tree view from the database..
                            contractFileViewModel.ResourceType = EnumGlobal.ResourceType.Contract.ToString();
                        }
                        else if ((parentid == Guid.Empty || parentid != null) && ContentResourceGuid == Guid.Empty)
                        {
                            if (resourceKey.ToUpper() != EnumGlobal.ResourceType.ContractCloseOut.ToString().ToUpper())
                            {
                                var contractResourceFile = _contractResourceFileService.GetFilePathByResourceIdAndKeys(EnumGlobal.ResourceType.Base.ToString(), resourceId);
                                contractFileViewModel.ParentId = contractResourceFile.ContractResourceFileGuid;
                                contractFileViewModel.keys     = EnumGlobal.ResourceType.Base.ToString();
                                //contractFileViewModel.ResourceType = resourceKey;
                                //for task order also resourcetype is Contract to show in the tree view from the database..
                                contractFileViewModel.ResourceType = EnumGlobal.ResourceType.Contract.ToString();
                            }
                        }

                        if (resourceKey.ToUpper() == EnumGlobal.ResourceType.ContractCloseOut.ToString().ToUpper())
                        {
                            contractFileViewModel.ResourceType = EnumGlobal.ResourceType.Contract.ToString();
                        }

                        var fileEntity = _mapper.Map <ContractResourceFile>(contractFileViewModel);

                        _contractRefactorService.InsertContractFile(fileEntity);

                        //auditlog..
                        AuditLogForUploadDownload(fileEntity, CrudTypeForAdditionalLogMessage.Uploaded.ToString());
                    }
                }

                //If existing file/s description have been changed
                if (fileInfo.Length > Request.Form.Files.Count)
                {
                    for (int i = Request.Form.Files.Count; i <= fileInfo.Length - 1; i++)
                    {
                        var fileInfoObj = fileInfo[i].Split(',');

                        var fileById = _contractRefactorService.GetFilesByContractFileGuid(new Guid(fileInfoObj[0]));
                        if (fileById != null)
                        {
                            fileById.Description = WebUtility.UrlDecode(fileInfoObj[1]);
                            _contractRefactorService.UpdateFile(fileById);
                        }
                    }
                }

                return(Ok(true));
            }
            catch (Exception ex)
            {
                return(BadRequestFormatter.BadRequest(this, ex));
            }
        }