Beispiel #1
0
        public static string SynchPoint(int customerId)
        {
            IMemberCardService     memberCardService     = DependencyResolver.Current.GetService <IMemberCardService>();
            IMemberCardTypeService memberCardTypeService = DependencyResolver.Current.GetService <IMemberCardTypeService>();
            var points = SqlHelper.QuerySP <HistoryPointViewModel>("spSale_HistoryPoint", new
            {
                CustomerId = customerId
            });

            if (points != null && points.Count() > 0)
            {
                var point = points.FirstOrDefault();
                if (point.MemberCardId != null)
                {
                    var memberCard     = memberCardService.Get(point.MemberCardId.Value);
                    var memberCardType = memberCardTypeService.GetByPoint(point.AccumulatedPoint);
                    if (memberCardType != null)
                    {
                        memberCard.MemberCardTypeId = memberCardType.Id;
                        memberCardService.Update(memberCard);
                    }
                }
            }
            return(null);
        }
Beispiel #2
0
        public static string SynchUpdateTypeCrad(int customerId, double?accumulated, double?used, int?frequency, bool addition = true)
        {
            ICustomerRepository    CustomerRepository    = DependencyResolver.Current.GetService <ICustomerRepository>();
            IMemberCardService     memberCardService     = DependencyResolver.Current.GetService <IMemberCardService>();
            IMemberCardTypeService memberCardTypeService = DependencyResolver.Current.GetService <IMemberCardTypeService>();
            var      customer  = CustomerRepository.GetCustomerById(customerId);
            DateTime aDateTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);

            if (customer != null)
            {
                if (addition)
                {
                    customer.Point         += accumulated;
                    customer.PaidPoint     += used;
                    customer.RemainingPoint = customer.Point - customer.PaidPoint;
                }
                else
                {
                    customer.Point         -= accumulated;
                    customer.PaidPoint     -= used;
                    customer.RemainingPoint = customer.Point - customer.PaidPoint;
                }
                if (frequency != null)
                {
                    customer.Frequency             = frequency;
                    customer.EndDateProductInvoice = aDateTime;
                }
                CustomerRepository.UpdateCustomer(customer);
                if (customer.MemberCardId != null)
                {
                    var memberCard     = memberCardService.Get(customer.MemberCardId.Value);
                    var memberCardType = memberCardTypeService.GetByPoint(customer.Point);
                    if (memberCardType != null)
                    {
                        memberCard.MemberCardTypeId = memberCardType.Id;
                        memberCardService.Update(memberCard);
                    }
                }
            }
            return(null);
        }
Beispiel #3
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));
        }