private void InsertFarContract(DMFarClause farClause, Guid userGuid, Guid contractGuid, string clauseNumber)
        {
            farContractEntity = new FarContract();
            var dbFarClause   = _farClauseService.GetFarClauseByNumber(clauseNumber);
            var farClauseGuid = Guid.Empty;

            if (dbFarClause != null)
            {
                farClauseGuid = dbFarClause.FarClauseGuid;
            }

            if (farClause.FarContractTypeGuid == Guid.Empty)
            {
                var contractType = _farContractTypeService.GetByCode(this.otherFarContractTypeCode);
                if (contractType != null)
                {
                    farClause.FarContractTypeGuid = contractType.FarContractTypeGuid;
                }
            }

            var farContractTypeClause = _farContractTypeClauseService.GetByFarClauseFarContractTypeGuid(farClauseGuid, farClause.FarContractTypeGuid);

            if (farContractTypeClause != null)
            {
                farContractEntity.FarContractTypeClauseGuid = farContractTypeClause.FarContractTypeClauseGuid;
                farContractEntity.IsDeleted    = false;
                farContractEntity.CreatedBy    = userGuid;
                farContractEntity.UpdatedBy    = userGuid;
                farContractEntity.CreatedOn    = DateTime.UtcNow;
                farContractEntity.UpdatedOn    = DateTime.UtcNow;
                farContractEntity.ContractGuid = contractGuid;
                _farContractService.Add(farContractEntity);
                farClause.ImportStatus = ImportStatus.Success.ToString();
                farClause.Reason       = $"Far Clause added for project number {farClause.ProjectNumber} has been added successfully";
            }
            else
            {
                farClause.ImportStatus = ImportStatus.Fail.ToString();
                farClause.Reason      += $"Far Clause mapping not found for project number {farClause.ProjectNumber} on {clauseNumber}.";
            }
        }
Exemplo n.º 2
0
        public IActionResult Edit([FromBody] FarClauseViewModel farClauseViewModel)
        {
            try
            {
                var farClauseEntity = Models.ObjectMapper <FarClauseViewModel, Core.Entities.FarClause> .Map(farClauseViewModel);

                if (ModelState.IsValid)
                {
                    if (!ModelState.IsValid)
                    {
                        return(BadRequest(ModelState));
                    }
                    farClauseEntity.UpdatedBy = UserHelper.CurrentUserGuid(HttpContext);

                    //update the farclause..
                    _farClauseService.Edit(farClauseEntity);

                    //now get body stream.. to edit FarContractTypeCaluse table....
                    Stream req = Request.Body;
                    req.Seek(0, SeekOrigin.Begin);
                    string json = new StreamReader(req).ReadToEnd();

                    var dictValues = JsonConvert.DeserializeObject <Dictionary <string, object> >(json);

                    foreach (KeyValuePair <string, object> entry in dictValues)
                    {
                        var farContractType = _farContractTypeService.GetByCode(entry.Key);
                        if (farContractType != null)
                        {
                            var farContractTypeCaluse = _farContractTypeClauseService.GetByFarClauseFarContractTypeGuid(farClauseViewModel.FarClauseGuid, farContractType.FarContractTypeGuid);

                            if (farContractTypeCaluse == null)
                            {
                                //add if there is no farcontracttypeclause record..
                                FarContractTypeClause farContractTypeCaluseEntity = new FarContractTypeClause
                                {
                                    FarClauseGuid       = farClauseEntity.FarClauseGuid,
                                    FarContractTypeGuid = farContractType.FarContractTypeGuid,
                                    UpdatedBy           = UserHelper.CurrentUserGuid(HttpContext),
                                    IsDeleted           = false,
                                    IsRequired          = false,
                                    IsApplicable        = false,
                                    IsOptional          = false
                                };

                                if (entry.Value.Equals("Required"))
                                {
                                    farContractTypeCaluseEntity.IsRequired = true;
                                }
                                else if (entry.Value.Equals("Applicable"))
                                {
                                    farContractTypeCaluseEntity.IsApplicable = true;
                                }
                                else if (entry.Value.Equals("Optional"))
                                {
                                    farContractTypeCaluseEntity.IsOptional = true;
                                }
                                _farContractTypeClauseService.Add(farContractTypeCaluseEntity);
                                continue;
                            }
                            farContractTypeCaluse.UpdatedBy = UserHelper.CurrentUserGuid(HttpContext);
                            farContractTypeCaluse.IsDeleted = false;

                            farContractTypeCaluse.IsRequired   = false;
                            farContractTypeCaluse.IsApplicable = false;
                            farContractTypeCaluse.IsOptional   = false;

                            if (entry.Value.Equals("Required"))
                            {
                                farContractTypeCaluse.IsRequired = true;
                            }
                            else if (entry.Value.Equals("Applicable"))
                            {
                                farContractTypeCaluse.IsApplicable = true;
                            }
                            else if (entry.Value.Equals("Optional"))
                            {
                                farContractTypeCaluse.IsOptional = true;
                            }
                            _farContractTypeClauseService.Edit(farContractTypeCaluse);
                        }
                        //edit here
                    }

                    //audit log..
                    var additionalInformation    = string.Format("{0} {1} the {2}", User.FindFirst("fullName").Value, CrudTypeForAdditionalLogMessage.Edited.ToString(), "Far Clause");
                    var additionalInformationURl = _configuration.GetSection("SiteUrl").Value + ("/Admin/FarClause");

                    string[] resourceTitles = { "ResourceTitle", "GUID", "Number", "Title" };
                    string[] resourceValues = { "Far Clause", farClauseEntity.FarClauseGuid.ToString(), farClauseEntity.Number, farClauseEntity.Title };
                    var      resource       = FormatHelper.AuditLogResourceFormat(resourceTitles, resourceValues);

                    AuditLogHandler.InfoLog(_logger, User.FindFirst("fullName").Value, UserHelper.CurrentUserGuid(HttpContext), farClauseEntity, resource, farClauseEntity.FarClauseGuid, UserHelper.GetHostedIp(HttpContext), "Far Clause Edited", Guid.Empty, "Successful", "", additionalInformation, additionalInformationURl);
                    //end of log..

                    return(Ok(new { status = ResponseStatus.success.ToString(), message = "Successfully Updated !!" }));
                }
                else
                {
                    return(View(farClauseEntity));
                }
            }
            catch (ArgumentException ex)
            {
                ModelState.AddModelError("", ex.Message);
                return(BadRequestFormatter.BadRequest(this, ex));;
            }
            catch (Exception e)
            {
                ModelState.AddModelError("", e.Message);
                return(BadRequestFormatter.BadRequest(this, e));
            }
        }