Exemple #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(int?Id)
        {
            var Commision = CommisionRepository.GetCommisionById(Id.Value);

            if (Commision != null && Commision.IsDeleted != true)
            {
                var model = new CommisionViewModel();
                AutoMapper.Mapper.Map(Commision, model);

                if (model.CreatedUserId != Erp.BackOffice.Helpers.Common.CurrentUser.Id && Erp.BackOffice.Helpers.Common.CurrentUser.UserTypeId != 1)
                {
                    TempData["FailedMessage"] = Wording.NotOwner;
                    return(RedirectToAction("Index"));
                }

                var listCommisionSale = CommisionSaleRepository.GetAllCommisionSale().Where(x => x.CommisionId == Commision.Id).FirstOrDefault();
                if (listCommisionSale != null)
                {
                    TempData["FailedMessage"] = Wording.CommisionApplied;
                    return(RedirectToAction("Index"));
                }

                ViewBag.branchList = BranchRepository.GetAllBranch().Where(x => x.Id == Helpers.Common.CurrentUser.BranchId || Helpers.Common.CurrentUser.UserTypeId == 1).AsEnumerable().Select(x => new
                                                                                                                                                                                                 SelectListItem {
                    Text = x.Name, Value = x.Id + ""
                }).ToList();

                var listCommisionBranch = CommisionRepository.GetListCommisionBranch(Commision.Id).ToList();

                model.BranchIdList = listCommisionBranch.Select(x => x.BranchId.ToString()).ToArray();

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