Пример #1
0
        public ActionResult Create(MemberCardViewModel model, bool?IsInvoice)
        {
            if (ModelState.IsValid)
            {
                var MemberCard = MemberCardService.GetMemberCardByCode(model.Code);
                if (MemberCard != null)
                {
                    TempData[Globals.FailedMessageKey] = "Mã thẻ đã được cấp";
                    return(RedirectToAction("Create", new { CustomerId = model.CustomerId, IsPopup = true, IsInvoice = IsInvoice }));
                }
                var customer       = CustomerRepository.GetCustomerById(model.CustomerId.Value);
                var MemberCardType = MemberCardTypeService.MemberCardTypeGetById(model.MemberCardTypeId.Value);
                ProductOutboundController.CreateForMemberCard(TempData, MemberCardType.CardId, Helpers.Common.CurrentUser.BranchId, customer.Name, customer.Code);
                if (TempData[Globals.FailedMessageKey] != null)
                {
                    return(RedirectToAction("Create", new { CustomerId = model.CustomerId, IsPopup = true, IsInvoice = IsInvoice }));
                }

                if (customer.MemberCardId != null)
                {
                    var memberCard_Before = MemberCardService.GetMemberCardById(customer.MemberCardId.Value);
                    if (memberCard_Before != null)
                    {
                        memberCard_Before.Status = MemberCardViewModel.Inactive;
                        MemberCardService.Update(memberCard_Before);
                    }
                }

                MemberCard = new MemberCard();
                AutoMapper.Mapper.Map(model, MemberCard);
                SetModifier(MemberCard);
                MemberCard.DateOfIssue = DateTime.Now;
                MemberCard.Status      = MemberCardViewModel.Active;
                MemberCardService.Create(MemberCard);
                //Thay đổi thẻ cho khách hàng
                customer.MemberCardId = MemberCard.Id;
                CustomerRepository.UpdateCustomer(customer);

                TempData[Globals.SuccessMessageKey] += App_GlobalResources.Wording.InsertSuccess;
                if (IsInvoice == true)
                {
                    ViewBag.closePopup       = "close Popup";
                    model.ListMemberCardType = MemberCardTypeService.Get()
                                               .Select(item => new MemberCardTypeViewModel
                    {
                        Id    = item.Id,
                        Name  = item.Name,
                        Image = item.Image
                    })
                                               .OrderBy(item => item.Name)
                                               .ToList();
                    return(View(model));
                }
                if (Request["IsPopup"] != null && Request["IsPopup"].ToString().ToLower().Equals("true"))
                {
                    return(RedirectToAction("_ClosePopup", "Home", new { area = "", FunctionCallback = "ClosePopupAndReloadPage" }));
                }
                return(RedirectToAction("Index"));
            }
            return(View(model));
        }
Пример #2
0
        public ActionResult Create(CustomerViewModel model, bool?IsAppend)
        {
            if (ModelState.IsValid)
            {
                //Tạo thẻ cho khách hàng
                if (model.IsCreateCard == true)
                {
                    if (model.MemberCardTypeId == null)
                    {
                        TempData[Globals.FailedMessageKey] = "Vui lòng chọn loại thẻ";
                        ViewBag.FailedMessage = TempData["FailedMessage"];
                        return(View(model));
                    }
                    var MemberCard = MemberCardService.GetMemberCardByCode(model.MemberCardCode);
                    if (MemberCard != null)
                    {
                        TempData[Globals.FailedMessageKey] = "Mã thẻ đã đã tồn tại, Vui lòng kiểm tra lại";
                        ViewBag.FailedMessage = TempData["FailedMessage"];
                        return(View(model));
                    }
                }
                var Customer = new Domain.Account.Entities.Customer();
                AutoMapper.Mapper.Map(model, Customer);
                Customer.IsDeleted      = false;
                Customer.CreatedUserId  = WebSecurity.CurrentUserId;
                Customer.ModifiedUserId = WebSecurity.CurrentUserId;
                Customer.CreatedDate    = DateTime.Now;
                Customer.ModifiedDate   = DateTime.Now;
                Customer.BranchId       = Helpers.Common.CurrentUser.BranchId;
                Customer.NameSearch     = Helpers.Common.ChuyenThanhKhongDau(Customer.Name);
                Customer.Point          = 0;
                Customer.PaidPoint      = 0;
                Customer.RemainingPoint = 0;
                Customer.Frequency      = 0;
                CustomerRepository.InsertCustomer(Customer);
                Customer.Code = Erp.BackOffice.Helpers.Common.GetOrderNo("Customer");
                CustomerRepository.UpdateCustomer(Customer);
                Erp.BackOffice.Helpers.Common.SetOrderNo("Customer");
                ////tạo liên hệ cho khách hàng
                //if (string.IsNullOrEmpty(model.FirstName) == false && string.IsNullOrEmpty(model.LastName) == false)
                //{
                //    var contact = new Domain.Account.Entities.Contact();
                //    AutoMapper.Mapper.Map(model, contact);
                //    contact.IsDeleted = false;
                //    contact.CreatedUserId = WebSecurity.CurrentUserId;
                //    contact.ModifiedUserId = WebSecurity.CurrentUserId;
                //    contact.CreatedDate = DateTime.Now;
                //    contact.ModifiedDate = DateTime.Now;
                //    contact.CustomerId = Customer.Id;

                //    ContactRepository.InsertContact(contact);
                //}

                ////tạo đặc tính động cho sản phẩm nếu có danh sách đặc tính động truyền vào và đặc tính đó phải có giá trị
                //ObjectAttributeController.CreateOrUpdateForObject(Customer.Id, model.AttributeValueList);

                if (model.IsCreateCard == true)
                {
                    var MemberCardType = MemberCardTypeService.MemberCardTypeGetById(model.MemberCardTypeId.Value);
                    if (MemberCardType != null)
                    {
                        ProductOutboundController.CreateForMemberCard(TempData, MemberCardType.CardId, Helpers.Common.CurrentUser.BranchId, Customer.Name, Customer.Code);
                        if (TempData[Globals.FailedMessageKey] != null)
                        {
                            TempData[Globals.FailedMessageKey] += "Chưa cấp được thẻ cho khách hàng! </br>";
                        }
                        else
                        {
                            var memberCard = new MemberCard();
                            memberCard.IsDeleted        = false;
                            memberCard.CreatedUserId    = WebSecurity.CurrentUserId;
                            memberCard.CreatedDate      = DateTime.Now;
                            memberCard.DateOfIssue      = DateTime.Now;
                            memberCard.Status           = MemberCardViewModel.Active;
                            memberCard.Code             = model.MemberCardCode;
                            memberCard.CustomerId       = Customer.Id;
                            memberCard.MemberCardTypeId = MemberCardType.Id;
                            MemberCardService.Create(memberCard);

                            //Thay đổi thẻ cho khách hàng
                            Customer.MemberCardId = memberCard.Id;
                            CustomerRepository.UpdateCustomer(Customer);
                            TempData[Globals.SuccessMessageKey] = App_GlobalResources.Wording.InsertSuccess;
                        }
                    }
                }

                if (IsAppend == true)
                {
                    ViewBag.closePopup = "close and append to page parent";
                    model.Name         = model.Name;
                    model.Id           = Customer.Id;
                    return(View(model));
                }
                if (Request["IsPopup"] != null && Request["IsPopup"].ToString().ToLower().Equals("true"))
                {
                    return(RedirectToAction("_ClosePopup", "Home", new { area = "", FunctionCallback = "ClosePopupAndReloadPage" }));
                }
                return(RedirectToAction("Index"));
            }
            return(View(model));
        }