//Import mod attachment
        private void ImportContractModAttachment(FileConfiguration configuration, int nodeID, Guid contractGuid, bool isDelete)
        {
            var directoryFolderList = _importFileService.GetAllFolder(configuration.SourcePath + $"\\{nodeID}\\Mods\\", this.errorLogPath);

            foreach (var mod in directoryFolderList)
            {
                //mod attachment migration
                var modSourcePath = configuration.SourcePath + $"\\{nodeID}\\Mods\\" + mod;
                var modList       = _importFileService.GetAllFilesFromDirectory(modSourcePath, errorLogPath);
                var modDetail     = _contractModificationService.GetModByContractGuidAndModNumber(contractGuid, mod);
                if (modDetail != null)
                {
                    ImportContractAttachment(modList, EnumGlobal.ResourceType.ContractModification.ToString(), contractGuid, modDetail.ContractModificationGuid, isDelete);
                }
            }
        }
Esempio n. 2
0
        public IList <DMMods> ImportMods(List <DMMods> modsList, Guid userGuid)
        {
            var exportModsList = new List <DMMods>();
            var action         = string.Empty;

            foreach (var mods in modsList)
            {
                try
                {
                    if (!string.IsNullOrWhiteSpace(mods.Action))
                    {
                        action = mods.Action.ToLower();
                    }
                    if (!string.IsNullOrWhiteSpace(mods.ProjectNumber) &&
                        !string.IsNullOrWhiteSpace(mods.ModTitle) &&
                        !string.IsNullOrWhiteSpace(mods.ModNumber))
                    {
                        var contractGuid = _contractsService.GetContractGuidByProjectNumber(mods.ProjectNumber);
                        if (contractGuid != null && contractGuid != Guid.Empty)
                        {
                            mods.ContractGuid = contractGuid;
                            var dbMod = _contractModificationService.GetModByContractGuidAndModNumber(contractGuid, mods.ModNumber);
                            switch (action)
                            {
                            case "enable":
                            case "disable":
                            case "delete":
                                if (dbMod != null)
                                {
                                    var d = EnableDisableDeleteMods(mods, dbMod.ContractModificationGuid);
                                    mods.ImportStatus = d.ImportStatus.ToString();
                                    mods.Reason       = d.Reason;
                                }
                                else
                                {
                                    mods.ImportStatus = ImportStatus.Fail.ToString();
                                    mods.Reason       = "Mods not found";
                                }
                                break;

                            default:
                                var modValidation = ModsValidation(mods);
                                if (modValidation.IsValid)
                                {
                                    if (dbMod == null)
                                    {
                                        mods.ContractGuid             = contractGuid;
                                        mods.ContractModificationGuid = Guid.NewGuid();
                                        var checkMods = CheckDuplicateMods(mods);
                                        if (checkMods.IsValid == true)
                                        {
                                            InsertModsToDb(mods, userGuid);
                                            mods.ImportStatus = ImportStatus.Success.ToString();
                                            mods.Reason       = "Added successfully";
                                        }
                                        else
                                        {
                                            mods.ImportStatus = checkMods.ImportStatus;
                                            mods.Reason       = checkMods.Reason;
                                        }
                                    }
                                    else
                                    {
                                        mods.ContractModificationGuid = dbMod.ContractModificationGuid;
                                        var checkMods = CheckDuplicateMods(mods);
                                        if (checkMods.IsValid)
                                        {
                                            if (!string.IsNullOrWhiteSpace(mods.POPStart))
                                            {
                                                dbMod.POPStart = DateTime.Parse(mods.POPStart);
                                            }
                                            if (!string.IsNullOrWhiteSpace(mods.POPEnd))
                                            {
                                                dbMod.POPEnd = DateTime.Parse(mods.POPEnd);
                                            }

                                            var updatedValue = MapperHelper.MapObjectToEntity(mods, dbMod);
                                            var parsedMod    = (ContractModification)updatedValue;
                                            parsedMod.UpdatedOn = DateTime.UtcNow;
                                            parsedMod.UpdatedBy = userGuid;
                                            dbMod.FundingAmount = Decimal.Parse(mods.FundingAmount);
                                            dbMod.AwardAmount   = Decimal.Parse(mods.AwardAmount);
                                            UpdateModsToDb(parsedMod);
                                            mods.ImportStatus = ImportStatus.Success.ToString();
                                            mods.Reason       = "Updated successfully";
                                        }
                                        else
                                        {
                                            mods.ImportStatus = checkMods.ImportStatus;
                                            mods.Reason       = checkMods.Reason;
                                        }
                                    }
                                }
                                else
                                {
                                    mods.ImportStatus = ImportStatus.Fail.ToString();
                                    mods.Reason       = modValidation.Reason;
                                }
                                break;
                            }
                        }
                        else
                        {
                            mods.ImportStatus = ImportStatus.Fail.ToString();
                            mods.Reason       = "Contract doesn't exist";
                        }
                    }
                    else
                    {
                        if (string.IsNullOrWhiteSpace(mods.ProjectNumber))
                        {
                            mods.Reason = "Project number is empty";
                        }
                        else if (string.IsNullOrWhiteSpace(mods.ModTitle))
                        {
                            mods.Reason = "Mod title is empty";
                        }
                        else if (string.IsNullOrWhiteSpace(mods.ModNumber))
                        {
                            mods.Reason = "Mod number is empty";
                        }
                        mods.ImportStatus = ImportStatus.Fail.ToString();
                    }
                }
                catch (Exception ex)
                {
                    mods.Reason       = "Error while updating in database i.e: " + ex.Message;
                    mods.ImportStatus = ImportStatus.Fail.ToString();
                }
                exportModsList.Add(mods);
            }
            return(exportModsList);
        }