Beispiel #1
0
 private bool UpdateModsToDb(Core.Entities.ContractModification mods)
 {
     _contractModificationService.Edit(mods);
     return(true);
 }
        public IActionResult Edit([FromBody] ContractModificationViewModel contractModificationModel)
        {
            try
            {
                List <string> filePath      = new List <string>();
                bool          istriggered   = false;
                bool          isViewHistory = false;

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

                if (ModelState.IsValid)
                {
                    if (!ModelState.IsValid)
                    {
                        return(BadRequest(ModelState));
                    }
                    var contractId              = _contractService.GetContractIdByProjectId(contractModificationModel.ContractGuid);
                    var parentContractNumber    = _contractService.GetContractNumberById(contractId);
                    var taskOrderContractNumber = _contractService.GetContractNumberById(contractModificationModel.ContractGuid);
                    //var uploadPath = string.Format(
                    // $@"{parentContractNumber}\TaskOrder\{taskOrderContractNumber}\TaskOrderModification\{contractModificationModel.ModificationTitle}-{contractModificationModel.ModificationNumber}");

                    var contractModificationEntity = _mapper.Map <ContractModification>(contractModificationModel);
                    contractModificationEntity.IsTaskModification = true;
                    contractModificationEntity.UpdatedBy          = UserHelper.CurrentUserGuid(HttpContext);
                    contractModificationEntity.UpdatedOn          = CurrentDateTimeHelper.GetCurrentDateTime();

                    // for revenue and revenue notification
                    decimal?totalPreviousAwardAmount = 0.00M;
                    decimal?actualAmount             = 0.00M;
                    var     sumofAwardAmount         = _contractModificationService.GetTotalAwardAmount(contractModificationModel.ContractGuid);
                    if (sumofAwardAmount != null)
                    {
                        totalPreviousAwardAmount = (sumofAwardAmount.AwardAmount == null ? 0.00M : sumofAwardAmount.AwardAmount);
                    }
                    var previousAwardAmount = _contractModificationService.getAwardAndFundingAmountbyId(contractModificationModel.ContractModificationGuid);

                    if (previousAwardAmount.RevenueRecognitionGuid != Guid.Empty && previousAwardAmount.RevenueRecognitionGuid != null)
                    {
                        actualAmount = contractModificationModel.AwardAmount - previousAwardAmount.AwardAmount;
                    }
                    else
                    {
                        actualAmount = contractModificationModel.AwardAmount;
                    }

                    if (actualAmount < 0)
                    {
                        actualAmount = actualAmount * (-1);
                    }
                    decimal?currentAmount = totalPreviousAwardAmount + actualAmount;

                    string contractType = _contractService.GetContractType(contractModificationModel.ContractGuid);

                    if (RevenueRecognitionHelper.IsValidForRevenueRecognitionRequest(_configuration, contractType, currentAmount, 0.00M))
                    {
                        contractModificationEntity.IsUpdated = true;
                        _contractModificationService.UpdateRevenueRecognitionGuid(contractModificationEntity.ContractModificationGuid, contractModificationEntity.AwardAmount, contractModificationEntity.FundingAmount);
                        revenueGuid = AddNewRevenueAndUpdateContractModRevenueGuid(contractModificationEntity);
                        istriggered = true;



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

                    _contractModificationService.Edit(contractModificationEntity);

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

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

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

                    return(Ok(jsonObject));
                }
                else
                {
                    return(View(contractModificationModel));
                }
            }
            catch (ArgumentException ex)
            {
                ModelState.AddModelError("", ex.Message);
                return(BadRequestFormatter.BadRequest(this, ex));
            }
            catch (Exception ex)
            {
                ModelState.Clear();
                ModelState.AddModelError("", ex.Message);
                return(BadRequestFormatter.BadRequest(this, ex));
            }
        }