public IActionResult Add([FromBody] FarContractTypeClauseViewModel farContractTypeClauseViewModel) { try { var farContractTypeClauseModel = Models.ObjectMapper <FarContractTypeClauseViewModel, FarContractTypeClause> .Map(farContractTypeClauseViewModel); ///Checking duplicate far clause number is not applicable because there might have multiple same number with alternative titles.. if (_farContractTypeClauseService.CheckDuplicateByFarClauseAndFarContractTypeComposition(farContractTypeClauseModel) > 0) { var errorMessage = "Duplicate value entered for far clause number and far contract Type code !!"; ModelState.AddModelError("", errorMessage); return(BadRequestFormatter.BadRequest(this, errorMessage)); } farContractTypeClauseModel.UpdatedBy = UserHelper.CurrentUserGuid(HttpContext); farContractTypeClauseModel.IsDeleted = false; if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _farContractTypeClauseService.Add(farContractTypeClauseModel); return(Ok(new { status = ResponseStatus.success.ToString(), message = "Successfully Added !!" })); } catch (ArgumentException ex) { ModelState.AddModelError("", ex.Message); return(BadRequestFormatter.BadRequest(this, ex)); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); return(BadRequestFormatter.BadRequest(this, ex)); } }
public IActionResult Add([FromBody] FarClauseViewModel farClauseViewModel) { try { var farClauseEntity = Models.ObjectMapper <FarClauseViewModel, Core.Entities.FarClause> .Map(farClauseViewModel); ///Checking duplicate far clause number is not applicable because there might have multiple same number with alternative titles.. //if (_farClauseService.CheckDuplicateFarClauseNumber(farClauseEntity) > 0) //{ // var errorMessage = "Duplicate value entered for far clause number !!"; // ModelState.AddModelError("", errorMessage); // return BadRequest(ModelState); //} if (ModelState.IsValid) { farClauseEntity.FarClauseGuid = UserHelper.GetNewGuid(); farClauseEntity.UpdatedBy = UserHelper.CurrentUserGuid(HttpContext); farClauseEntity.IsDeleted = false; _farClauseService.Add(farClauseEntity); //now get body stream.. to save in 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) { FarContractTypeClause farContractTypeCaluseEntity = new FarContractTypeClause(); farContractTypeCaluseEntity.FarClauseGuid = farClauseEntity.FarClauseGuid; farContractTypeCaluseEntity.FarContractTypeGuid = farContractType.FarContractTypeGuid; farContractTypeCaluseEntity.UpdatedBy = UserHelper.CurrentUserGuid(HttpContext); farContractTypeCaluseEntity.IsDeleted = false; farContractTypeCaluseEntity.IsRequired = false; farContractTypeCaluseEntity.IsApplicable = false; farContractTypeCaluseEntity.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); } //edit here } //audit log.. var additionalInformation = string.Format("{0} {1} the {2}", User.FindFirst("fullName").Value, CrudTypeForAdditionalLogMessage.Added.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 = Infrastructure.Helpers.FormatHelper.AuditLogResourceFormat(resourceTitles, resourceValues); AuditLogHandler.InfoLog(_logger, User.FindFirst("fullName").Value, UserHelper.CurrentUserGuid(HttpContext), farClauseEntity, resource, farClauseEntity.FarClauseGuid, UserHelper.GetHostedIp(HttpContext), "Far Clause Added", Guid.Empty, "Successful", "", additionalInformation, additionalInformationURl); //end of log.. return(Ok(new { status = ResponseStatus.success.ToString(), message = "Successfully Added !!" })); } else { return(BadRequest(ModelState)); } } catch (Exception e) { ModelState.AddModelError("", e.Message); return(BadRequestFormatter.BadRequest(this, e)); } }