Exemple #1
0
        public ActionResult SaveIndividualCustomer(IndividualCustomerViewModel model, ActionType actionType)
        {
            Logger.Debug("SaveIndividualCustomer|Action type: " + actionType);

            if (actionType == ActionType.Save)
            {
                try
                {
                    if (CustomerBO.CheckIfIdCombinationExists(
                            Int32.Parse(model.IdType), model.IdNumber, model.IdIssuedCountry, model.Id))
                    {
                        TempData["MessageType"]        = MessageType.Error;
                        TempData["MessageDescription"] = CommonResources.MessageIdAlreadyExists;

                        TempData["CustomerDetailModel"] = model;
                        return(RedirectToAction("ViewCustomerDetails"));
                    }

                    IIndividualCustomerVO customer = (IndividualCustomerVO)
                                                     CustomerMapper.Map(model, typeof(IndividualCustomerViewModel), typeof(IndividualCustomerVO));
                    customer.LastUpdateBy = User.Identity.Name;

                    if (customer.Id == 0)
                    {
                        customer = CustomerBO.CreateIndividualCustomer(customer);
                    }
                    else
                    {
                        IIndividualCustomerVO sessionCustomer = (IIndividualCustomerVO)Session["SessionCustomer"];
                        customer = CustomerBO.UpdateIndividualCustomer(sessionCustomer, customer);
                    }

                    model = (IndividualCustomerViewModel)
                            CustomerMapper.Map(customer, typeof(IIndividualCustomerVO), typeof(IndividualCustomerViewModel));

                    Session["SessionCustomer"]     = customer;
                    TempData["MessageType"]        = MessageType.Success;
                    TempData["MessageDescription"] = CommonResources.MessageSaveSuccess;
                }
                catch (Exception exception)
                {
                    Logger.Debug("Exception encountered: " + exception.StackTrace);

                    TempData["MessageType"]        = MessageType.Error;
                    TempData["MessageDescription"] = CommonResources.MessageSaveError + exception.Message;
                }

                TempData["CustomerDetailModel"] = model;
                return(RedirectToAction("ViewIndividualDetails"));
            }

            return(RedirectToAction("Welcome", "Home"));
        }