Example #1
0
        public ActionResult Detail(CommisionDetailViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (Request["Submit"] == "Save")
                {
                    foreach (var item in model.DetailList)
                    {
                        if (item.CommissionValue < 0)
                        {
                            item.CommissionValue = 0;
                        }
                        else if ((item.IsMoney == null || item.IsMoney == false) && item.CommissionValue > 100)
                        {
                            item.CommissionValue = 100;
                        }
                        else if (item.CommissionValue > item.Price)
                        {
                            item.CommissionValue = item.Price;
                        }

                        if (item.Id > 0)
                        {
                            var commision = commisionRepository.GetCommisionById(item.Id);
                            commision.ModifiedUserId  = WebSecurity.CurrentUserId;
                            commision.ModifiedDate    = DateTime.Now;
                            commision.CommissionValue = item.CommissionValue;
                            commision.IsMoney         = item.IsMoney;
                            commisionRepository.UpdateCommision(commision);
                        }
                        else
                        {
                            if (item.CommissionValue > 0)
                            {
                                var commision = new Commision();
                                commision.IsDeleted       = false;
                                commision.CreatedUserId   = WebSecurity.CurrentUserId;
                                commision.ModifiedUserId  = WebSecurity.CurrentUserId;
                                commision.CreatedDate     = DateTime.Now;
                                commision.ModifiedDate    = DateTime.Now;
                                commision.BranchId        = model.BranchId;
                                commision.StaffId         = model.StaffId;
                                commision.ProductId       = item.ProductId;
                                commision.CommissionValue = item.CommissionValue;
                                commision.IsMoney         = item.IsMoney;
                                commisionRepository.InsertCommision(commision);
                            }
                        }
                    }

                    TempData[Globals.SuccessMessageKey] = App_GlobalResources.Wording.UpdateSuccess;
                    return(RedirectToAction("Detail", new { BranchId = model.BranchId, StaffId = model.StaffId }));
                }

                return(View(model));
            }

            return(View(model));
        }
        public ActionResult Edit(CommisionViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (Request["Submit"] == "Save")
                {
                    var Commision = CommisionRepository.GetCommisionById(model.Id);
                    AutoMapper.Mapper.Map(model, Commision);
                    Commision.ModifiedUserId = WebSecurity.CurrentUserId;
                    Commision.ModifiedDate   = DateTime.Now;
                    CommisionRepository.UpdateCommision(Commision);

                    var listCommisionBranch = CommisionRepository.GetListCommisionBranch(Commision.Id).ToList();
                    for (int i = 0; i < listCommisionBranch.Count; i++)
                    {
                        CommisionRepository.DeleteCommisionBranch(listCommisionBranch[i].Id);
                    }

                    if (model.BranchIdList != null)
                    {
                        foreach (var id in model.BranchIdList)
                        {
                            CommisionRepository.InsertCommisionBranch(new CommisionBranch {
                                BranchId = Convert.ToInt32(id), CommisionId = Commision.Id
                            });
                        }
                    }

                    TempData[Globals.SuccessMessageKey] = App_GlobalResources.Wording.UpdateSuccess;
                    return(RedirectToAction("Index"));
                }

                return(View(model));
            }

            return(View(model));

            //if (Request.UrlReferrer != null)
            //    return Redirect(Request.UrlReferrer.AbsoluteUri);
            //return RedirectToAction("Index");
        }