예제 #1
0
        public IHttpActionResult PromoCodeStatusPost(string promoName)
        {
            //int userId = GetUserId();
            //if (userId == 0)
            //{
            //    reqResponse.ErrorMessages.Add("noUser", "Invalid Data");
            //    return Ok(reqResponse);
            //}
            using (PromoCodeRepository promoRepo = new PromoCodeRepository())
            {
                DomainModel.PromoCode promoCode = promoRepo.GetByName(promoName);
                if (promoCode == null)
                {
                    reqResponse.ErrorMessages.Add("invalid", "Invalid Promo Code!");
                }
                else
                {
                    if (promoCode.IsDeleted == true)
                    {
                        reqResponse.ErrorMessages.Add("invalid", "Invalid Promo Code!");
                    }
                    else
                    {
                        reqResponse.ResponseIdStr  = promoCode == null ? "" : promoCode.Id.ToString();
                        reqResponse.ReturnedObject = promoCode.Percentage;
                    }
                }


                return(Ok(reqResponse));
            }
        }
예제 #2
0
        public ActionResult Index(int?id)
        {
            ViewBag.ActiveMenu = 1;

            PromoCode areaModel = new PromoCode();

            if (id != null)
            {
                using (PromoCodeRepository vehiclesProxy = new PromoCodeRepository())
                {
                    areaModel = vehiclesProxy.GetById((int)id);
                }

                return(PartialView("_AddPromo", areaModel));
            }
            else
            {
                if (Request.IsAjaxRequest())
                {
                    return(PartialView("_AddPromo", areaModel));
                }
                else
                {
                    return(View(areaModel));
                }
            }
        }
예제 #3
0
        public PromoFormViewModel(int promoID)
        {
            var promoRepository = new PromoCodeRepository();

            try
            {
                var promoCode = promoRepository.Find(promoID);

                ID          = promoCode.ID;
                Code        = promoCode.Code;
                Name        = promoCode.Name;
                Description = promoCode.Description;
                Message     = promoCode.Message;
                Document    = promoCode.Document;
                StartDate   = promoCode.StartDate.ToShortDateString();
                EndDate     = promoCode.EndDate.ToShortDateString();
                Active      = promoCode.Active;
                Markup      = promoCode.Markup;
            }
            catch (Exception)
            {
                // record not found in db, return -1 for ID
                ID = -1;
            }
        }
        public List <PromoListViewModel> ListPromoCodes(string s)
        {
            var promoRepository = new PromoCodeRepository();

            IQueryable <PromoCode> promoCodes = promoRepository.FindByName(s).OrderByDescending(n => n.Name);

            return(promoCodes.Select(promo => new PromoListViewModel {
                promoCode = promo
            }).ToList());
        }
        public List <PromoListViewModel> ListPromoCodes()
        {
            var promoRepository = new PromoCodeRepository();

            var promoCodes = promoRepository.ListPromoCodes();

            return(promoCodes.Select(promo => new PromoListViewModel {
                promoCode = promo
            }).ToList());
        }
        public ActionResult DeleteConfirmed(int id)
        {
            // TODO: Maybe move delete logic to viewModel?
            var repository = new PromoCodeRepository();

            repository.Delete(id);
            repository.Save();

            return(RedirectToAction("List"));
        }
예제 #7
0
        public ActionResult loadData(String searchtoken)
        {
            PromoCodeRepository areaProxy = new PromoCodeRepository();

            // get start (paging start index) and length (page size for pagging)
            var draw   = Request.Form.GetValues("draw").FirstOrDefault();
            var start  = Request.Form.GetValues("start").FirstOrDefault();
            var length = Request.Form.GetValues("length").FirstOrDefault();
            // get sort columns value
            var sortColumn =
                Request.Form.GetValues("columns[" + Request.Form.GetValues("order[0][column]").FirstOrDefault() +
                                       "][name]").FirstOrDefault();
            var sortColumnDir = Request.Form.GetValues("order[0][dir]").FirstOrDefault();
            int pageSize      = length != null?Convert.ToInt32(length) : 0;

            int skip = start != null?Convert.ToInt32(start) : 0;

            var v = areaProxy.get(skip, pageSize, searchtoken, sortColumn, sortColumnDir)
                    .Distinct().ToList();//.OrderBy(sortColumn + " " + sortColumnDir)

            int totalRecords = areaProxy.Getcount(searchtoken);
            var toSerialize  = new
            {
                draw            = draw,
                recordsFiltered = totalRecords,
                recordsTotal    = totalRecords,

                data = v.Select(r => new
                {
                    r.Id,
                    Name       = r.Name,
                    Percentage = r.Percentage,
                    IsDelete   = r.IsDeleted
                }).AsQueryable()
            };

            var test = Json(
                toSerialize,
                JsonRequestBehavior.AllowGet);

            return(test);
        }
예제 #8
0
        public bool Save(PromoFormViewModel viewModel)
        {
            var promoRepository  = new PromoCodeRepository();
            var sourceRepository = new SourceRepository();

            var promoCode = new PromoCode
            {
                ID          = viewModel.ID,
                Code        = viewModel.Code,
                Name        = viewModel.Name,
                Description = viewModel.Description,
                Message     = viewModel.Message,
                Document    = viewModel.Document,
                StartDate   = DateTime.Parse(viewModel.StartDate),
                EndDate     = DateTime.Parse(viewModel.EndDate),
                Active      = viewModel.Active,
                Markup      = viewModel.Markup
            };

            var source = sourceRepository.FindByName(promoCode.Code + " Opt-In") ?? new Source
            {
                Name      = promoCode.Code + " Opt-In",
                Notes     = "Opt-In for " + promoCode.Code + " Promo Code",
                StartDate = promoCode.StartDate,
                EndDate   = promoCode.EndDate
            };

            try
            {
                sourceRepository.InsertOrUpdate(source);
                sourceRepository.Save();

                promoRepository.InsertOrUpdate(promoCode);
                promoRepository.Save();

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
        private bool LookupPromoCode(string code)
        {
            var repository = new PromoCodeRepository();
            var codeLookup = repository.LookupByCode(code);

            if (codeLookup != null)
            {
                Code        = codeLookup.Code;
                Name        = codeLookup.Name;
                Description = codeLookup.Description;
                Message     = codeLookup.Message;
                Document    = codeLookup.Document;
                StartDate   = codeLookup.StartDate;
                EndDate     = codeLookup.EndDate;
                Active      = codeLookup.Active;
                Markup      = codeLookup.Markup;

                return(true);
            }
            return(false);
        }
예제 #10
0
        public ActionResult Add(PromoCode model)
        {
            if (model.Id == 0)
            {
                ModelState["Id"].Errors.Clear();
            }

            if (ModelState.IsValid)
            {
                using (PromoCodeRepository areaProxy = new PromoCodeRepository())
                {
                    reqResponse = areaProxy.AddUpdate(model);

                    return(Json(reqResponse, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                reqResponse.ErrorMessages.Add("invalidData", OperationLP.InvalidData);
                return(Json(reqResponse, JsonRequestBehavior.AllowGet));
            }
        }
예제 #11
0
        public IHttpActionResult Subscription(SubscriptionModel data)
        {
            int userId = GetUserId();

            if (userId == 0)
            {
                reqResponse.ErrorMessages.Add("noUser", "Invalid Data");
                return(Ok(reqResponse));
            }

            using (SecurityUserRepository secUserRepo = new SecurityUserRepository())
            {
                var currentUser = secUserRepo.GetById(userId);
                //data.Name = "ddd";
                //data.PhoneNumber = 2525;
                data.Name        = currentUser.FullName;
                data.PhoneNumber = int.Parse(currentUser.Telephone);
            }

            data.riderId = userId;

            if (string.IsNullOrEmpty(data.Name) || string.IsNullOrEmpty(data.PhoneNumber.ToString()) || data.PhoneNumber <= 0 || string.IsNullOrEmpty(data.Location) || string.IsNullOrEmpty(data.DateTimeStr))
            {
                reqResponse.ErrorMessages.Add("invalidD", "Invalid Data");

                return(Ok(reqResponse));
            }

            data.DateTimeStr = data.DateTimeStr;// + " " + data.TimeStr;

            if (!string.IsNullOrEmpty(data.PromoCodeName))
            {
                using (PromoCodeRepository promoRepo = new PromoCodeRepository())
                {
                    DomainModel.PromoCode promoCode = promoRepo.GetByName(data.PromoCodeName);
                    if (promoCode != null)
                    {
                        if (promoCode.IsDeleted != true)
                        {
                            data.PromoCodeId = promoCode.Id;
                        }
                    }


                    // return Ok(reqResponse);
                }
            }

            DateTime tempDate = new DateTime();

            try
            {
                tempDate = DateTime.ParseExact(data.DateTimeStr, "dd/MM/yyyy hh:mm tt", CultureInfo.InvariantCulture);
            }
            catch (Exception)
            {
                tempDate = DateTime.ParseExact(data.DateTimeStr, "yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture);
            }
            //DateTime ddd = DateTime.ParseExact(data.DateTimeStr,"dd/MM/yyyy hh:mm tt", CultureInfo.InvariantCulture);
            using (SubscriptionRepository subscriptionRepo = new SubscriptionRepository())
            {
                return(Ok(
                           subscriptionRepo.AddUpdate(new DomainModel.SubscriptionV()
                {
                    Name = data.Name,
                    PhoneNumber = data.PhoneNumber,
                    LocationStr = data.Location,
                    Lat = data.Lat,
                    Lng = data.Lng,
                    PickDateTime = tempDate,
                    DaysCount = data.DaysCount,
                    PromoCodeId = data.PromoCodeId,
                    UserId = data.riderId,
                    PayMobId = data.PayMobId
                })
                           ));
            }
        }