Exemplo n.º 1
0
        public ActionResult Edit([FromBody] CustomerViewModel customerViewModel)
        {
            try
            {
                // Mapping Done
                Customer customer     = new Customer();
                var      customerType = _customerTypeService.GetCustomerTypeByGuid(customerViewModel.CustomerTypeGuid);
                customer = ObjectMapper <CustomerViewModel, Customer> .Map(customerViewModel);

                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }
                if (customer.CustomerCode != "N/A" && customerType == EnumGlobal.CustomerType.Federal.ToString())
                {
                    if (_customerService.CheckDuplicates(customer) > 0)
                    {
                        ModelState.AddModelError("", "Duplicate value entered for either code or name !!");
                        return(BadRequest(ModelState));
                    }
                }
                if (string.IsNullOrEmpty(customer.CustomerCode))
                {
                    customer.CustomerCode = "N/A";
                }
                //var customerdetails = _customerService.GetCustomerById(customer.CustomerGuid);
                customer.UpdatedOn = DateTime.Now;
                customer.UpdatedBy = UserHelper.CurrentUserGuid(HttpContext);

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

                var additionalInformationWithUri = string.Format("<a href=\"{0}\">{1}</a>", additionalInformationURl, additionalInformation);

                var resource = string.Format("{0} </br> GUID: {1} </br> Customer Name: {2} </br> Customer Code: {3}", ResourceType.Customer.ToString(), customer.CustomerGuid, customer.CustomerName, customer.CustomerCode);

                AuditLogHandler.InfoLog(_logger, User.FindFirst("fullName").Value, UserHelper.CurrentUserGuid(HttpContext), customer, resource, customer.CustomerGuid, UserHelper.GetHostedIp(HttpContext), "Customer Edited", Guid.Empty, "Successful", "", additionalInformationWithUri, additionalInformationURl);

                _customerService.Edit(customer);
                return(Ok(new { status = ResponseStatus.success.ToString(), message = "Successfully Updated !!" }));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                return(BadRequestFormatter.BadRequest(this, ex));
            }
        }