Exemplo n.º 1
0
        public IActionResult SavePromoCode([FromBody] PromoCodeModel promocode)
        {
            //string connectionString = configuration.GetSection("ConnectionString").GetSection("DefaultConnection").Value;

            try
            {
                string row = Data.PromoCode.SavePromoCode(promocode);

                if (row == "Success")
                {
                    return(StatusCode((int)HttpStatusCode.OK, "Saved Successfully"));
                }

                else
                {
                    return(StatusCode((int)HttpStatusCode.Forbidden, new { error = new { message = row } }));
                }
            }


            catch (Exception e)
            {
                if (e.Message.Contains("UNIQUE KEY constraint") == true)
                {
                    return(StatusCode((int)HttpStatusCode.InternalServerError, new { error = new { message = "PromoCode is already exists" } }));
                }
                else
                {
                    string SaveErrorLog = Data.Common.SaveErrorLog("SavePromoCode", e.Message);
                    return(StatusCode((int)HttpStatusCode.InternalServerError, new { error = new { message = e.Message.ToString() } }));
                }
            }
        }
Exemplo n.º 2
0
        public static string SavePromoCode(PromoCodeModel promocode)
        {
            try
            {
                string ConnectionString        = Common.GetConnectionString();
                List <SqlParameter> parameters = new List <SqlParameter>();
                parameters.Add(new SqlParameter("@PromocodeText", promocode.PromocodeText));
                parameters.Add(new SqlParameter("@PromoType", promocode.PromoType));
                parameters.Add(new SqlParameter("@PromocodeValue", promocode.PromocodeValue));
                parameters.Add(new SqlParameter("@NumberofUsePerUser", promocode.NumberofUsePerUser));
                parameters.Add(new SqlParameter("@StartDate", promocode.StartDate));
                parameters.Add(new SqlParameter("@ExpiryDate", promocode.ExpiryDate));


                using (DataSet dt = SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure, "spSavePromoCode", parameters.ToArray()))
                {
                    string rowsAffected = dt.Tables[0].Rows[0]["Status"].ToString();

                    return(rowsAffected);
                }
            }
            catch (Exception e)
            {
                //loggerErr.Error(e.Message + " - " + e.StackTrace);
                throw e;
            }
        }
        public Task UpdateCampaign(PromoCodeModel existingCampaign)
        {
            FilterDefinition <PromoCodeModel> filter = Builders <PromoCodeModel> .Filter.Eq(m => m._id, existingCampaign._id);

            var updateCampaign = Builders <PromoCodeModel> .Update.Set("CampaignName", existingCampaign.CampaignName).
                                 Set("NoOfPromoCodes", existingCampaign.NoOfPromoCodes).
                                 Set("PromocodeCost", existingCampaign.PromocodeCost).
                                 Set("StartDate", existingCampaign.StartDate).
                                 Set("EndDate", existingCampaign.EndDate).
                                 Set("Prefix", existingCampaign.Prefix).
                                 Set("PromocodeGenerated", existingCampaign.PromocodeGenerated).
                                 Set("Remarks", existingCampaign.Remarks).
                                 Set("CampaignCreatedDate", existingCampaign.CampaignCreatedDate).
                                 Set("CreatedUserName", existingCampaign.CreatedUserName).
                                 Set("CampaignStatus", existingCampaign.CampaignStatus).
                                 Set("CancellaionResaon", existingCampaign.CancellaionResaon).
                                 Set("CancelledDate", existingCampaign.CancelledDate).
                                 Set("CancelledUser", existingCampaign.CancelledUser).
                                 Set("PortalPercentage", existingCampaign.PortalPercentage).
                                 Set("FranschisePercentage", existingCampaign.FranschisePercentage).
                                 Set("ChefPercentage", existingCampaign.ChefPercentage);

            var result = this.promoCodeContext._promoCode.FindOneAndUpdateAsync(filter, updateCampaign);

            return(result);
        }
        public PromoCodeModel CreateNewCampaign(PromoCodeModel addNewCampaign)
        {
            RandomCode generateRandomCode = new RandomCode();

            generateRandomCode.randomMethod(addNewCampaign);
            this.promoCodeContext._promoCode.InsertOne(addNewCampaign);
            return(addNewCampaign);
        }
        public async Task <OrderDetailsModel> SetPromoCode(string orderId, string promoCode)
        {
            var url   = $"{_serviceUrl}/{orderId}/promocode";
            var model = new PromoCodeModel {
                Code = promoCode
            };

            var response = await Client.PostAsJsonAsync(url, model).ConfigureAwait(false);

            return(await response.Content.ReadAsAsync <OrderDetailsModel>());
        }
        // GET: AdminTH/PromoCode/Edit/5
        public ActionResult Edit(Guid id)
        {
            var promotion = _promotionDao.FindById(id);

            var model = new PromoCodeModel(promotion);

            if (promotion.TriggerSettings.Type != PromotionTriggerTypes.NoTrigger)
            {
                model.CanModifyTriggerGoal = !_promotionDao.GetProgressByPromo(id).Any();
            }

            return(View(model));
        }
        public async Task <bool> UpdatePromoCode(PromoCodeModel promoCodes)
        {
            PromoCodes code = new PromoCodes
            {
                Id            = promoCodes.Id,
                PromocodeName = promoCodes.PromocodeName,
                Code          = promoCodes.Code,
                Validity      = promoCodes.Validity,
                Discount      = promoCodes.Discount,
            };

            await _promoCodeRepository.UpdatePromoCode(code);

            return(true);
        }
        public async Task <bool> CreatePromoCode(PromoCodeModel promoCodes, Guid id)
        {
            PromoCodes code = new PromoCodes
            {
                PromocodeName = promoCodes.PromocodeName,
                Code          = promoCodes.Code,
                Validity      = promoCodes.Validity,
                Discount      = promoCodes.Discount,
                CreatedBy     = id,
                UpdatedBy     = id
            };

            await _promoCodeRepository.CreatePromoCode(code);

            return(true);
        }
Exemplo n.º 9
0
        public PromoCodeModel ApplyPromoCode(int loginid, string promocode)
        {
            PromoCodeModel data = new PromoCodeModel();

            using (evergreen_androidEntities context = new evergreen_androidEntities())
            {
                var result = context.promocodemasters.Where(x => x.LoginId == loginid && x.PromoCode == promocode).FirstOrDefault();
                if (result.PromoCodeId > 0)
                {
                    data.PromoCodeId = result.PromoCodeId;
                    data.PromoCode   = result.PromoCode;
                    data.Discount    = (decimal)result.Discount;
                    data.LoginId     = (int)result.LoginId;
                }
                return(data);
            }
        }
        public async Task <IActionResult> UpdateAsync(PromoCodeModel model)
        {
            try
            {
                var res = await Service.UpdatePromoCode(model);

                return(Ok(new ResponseViewModel <bool>
                {
                    Data = res,
                    Message = res ? TazzerCleanConstants.SavedSuccess : TazzerCleanConstants.GeneralError
                }));
            }
            catch (Exception ex)
            {
                _logger.LogError("An error has been thrown in UnitController:CreateAsync");
                return(BadRequest(ex));
            }
        }
Exemplo n.º 11
0
 public ActionResult AddPromoCode(PromoCodeModel m)
 {
     if (ModelState.IsValid)
     {
         using (var con = new SqlConnection(_connectionString))
         {
             var SessionModel = Session["User"] as SessionModel;
             var result       = con.Query <int>("Insert_into_MstPromoCode", new { m.PromoCode, m.Amount, m.FromDate, m.ToDate, SessionModel.UserId, SessionModel.CompanyId },
                                                commandType: CommandType.StoredProcedure).FirstOrDefault();
             if (result == 1)
             {
                 TempData["Message"] = "Submitted Successfully";
             }
             else
             {
                 TempData["Message"] = "Something Went Wrong";
             }
         }
     }
     return(RedirectToAction("Index"));
 }
        public void randomMethod(PromoCodeModel pcm)
        {
            var chars    = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
            var strChars = new char[6];

            //   Console.WriteLine("Enter n value:");
            int n = pcm.NoOfPromoCodes;

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < strChars.Length; j++)
                {
                    strChars[j] = chars[_random.Next(chars.Length)];
                }
                var finalString = new String(strChars);

                var promoCodeGenerated = pcm.Prefix + finalString;

                pcm.PromocodeGenerated += promoCodeGenerated + ",";
                // Console.WriteLine(finalString);
            }
        }
        public HttpResponseMessage ApplyPromoCode(PromoCodeModel model)
        {
            ResponseStatus response = new ResponseStatus();
            PromoCodeModel data     = new PromoCodeModel();

            try
            {
                if (Convert.ToInt64(model.LoginId) >= 0 && model.PromoCode != null)
                {
                    var result = _repository.ApplyPromoCode(model.LoginId, model.PromoCode);
                    if (result.PromoCode == model.PromoCode && result.LoginId == model.LoginId)
                    {
                        data.PromoCodeId   = result.PromoCodeId;
                        data.PromoCode     = result.PromoCode;
                        data.Discount      = (decimal)result.Discount;
                        data.LoginId       = (int)result.LoginId;
                        response.isSuccess = true;
                        return(Request.CreateResponse(HttpStatusCode.OK, new { data, response }));
                    }
                    else
                    {
                        response.serverResponseTime = System.DateTime.Now;
                        response.isSuccess          = false;
                        return(Request.CreateResponse(HttpStatusCode.BadRequest, new { response }));
                    }
                }
                else
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Something Worng !"));
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Something Worng !", ex));
            }
        }
        public ActionResult Edit(PromoCodeModel promoCode)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    var validationErrors = string.Join(", ",
                                                       ModelState.Values.Where(x => x.Errors.Count > 0)
                                                       .SelectMany(x => x.Errors)
                                                       .Select(x => x.ErrorMessage)
                                                       .ToArray());
                    throw new Exception(string.Format("Something's not right.{0}{1}", Environment.NewLine, validationErrors));
                }

                if (promoCode.TriggerSettings.Type == PromotionTriggerTypes.AmountSpent)
                {
                    promoCode.TriggerSettings.RideCount = 0;
                }
                else if (promoCode.TriggerSettings.Type == PromotionTriggerTypes.RideCount)
                {
                    promoCode.TriggerSettings.AmountSpent = 0;
                }
                else
                {
                    promoCode.TriggerSettings.RideCount   = 0;
                    promoCode.TriggerSettings.AmountSpent = 0;
                }

                if (!promoCode.CanModifyTriggerGoal)
                {
                    var promotion = _promotionDao.FindById(promoCode.Id);

                    promoCode.TriggerSettings.Type        = promotion.TriggerSettings.Type;
                    promoCode.TriggerSettings.AmountSpent = promotion.TriggerSettings.AmountSpent;
                    promoCode.TriggerSettings.RideCount   = promotion.TriggerSettings.RideCount;
                }

                _commandBus.Send(new UpdatePromotion
                {
                    PromoId                 = promoCode.Id,
                    Name                    = promoCode.Name,
                    Description             = promoCode.Description,
                    StartDate               = promoCode.StartDate,
                    EndDate                 = promoCode.EndDate,
                    DaysOfWeek              = promoCode.DaysOfWeek,
                    StartTime               = promoCode.StartTime,
                    EndTime                 = promoCode.EndTime,
                    AppliesToCurrentBooking = promoCode.AppliesToCurrentBooking,
                    AppliesToFutureBooking  = promoCode.AppliesToFutureBooking,
                    DiscountValue           = promoCode.DiscountValue,
                    DiscountType            = promoCode.DiscountType,
                    MaxUsagePerUser         = promoCode.MaxUsagePerUser,
                    MaxUsage                = promoCode.MaxUsage,
                    Code                    = promoCode.Code,
                    PublishedStartDate      = promoCode.PublishedStartDate,
                    PublishedEndDate        = promoCode.PublishedEndDate,
                    TriggerSettings         = promoCode.TriggerSettings
                });

                TempData["Info"] = string.Format("Promotion \"{0}\" updated", promoCode.Name);

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                ViewBag.Error = ex.Message;
                return(View(promoCode));
            }
        }
        public IActionResult CreateNewCampaign([FromBody] PromoCodeModel newPromoCodeModel)
        {
            var addedCampaignRecord = this.promoCodeService.AddNewCampaign(newPromoCodeModel);

            return(Ok(addedCampaignRecord));
        }
        public Task UpdateCampaign(PromoCodeModel existingCampaign)
        {
            var updateCampaign = this.promoCodeRepository.UpdateCampaign(existingCampaign);

            return(updateCampaign);
        }
        public PromoCodeModel AddNewCampaign(PromoCodeModel promoCodeModel)
        {
            promoCodeModel = this.promoCodeRepository.CreateNewCampaign(promoCodeModel);

            return(promoCodeModel);
        }
        public IActionResult UpdateCampaign([FromBody] PromoCodeModel updatePromoCodeModel)
        {
            var updatedCampaignRecord = this.promoCodeService.UpdateCampaign(updatePromoCodeModel);

            return(Ok(updatedCampaignRecord));
        }
Exemplo n.º 19
0
        public ActionResult AddPromoCode()
        {
            var promocode = new PromoCodeModel();

            return(PartialView(promocode));
        }
        public ActionResult Create(PromoCodeModel promoCode)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    var validationErrors = string.Join(", ",
                                                       ModelState.Values.Where(x => x.Errors.Count > 0)
                                                       .SelectMany(x => x.Errors)
                                                       .Select(x => x.ErrorMessage)
                                                       .ToArray());
                    throw new Exception(string.Format("Something's not right.{0}{1}", Environment.NewLine, validationErrors));
                }

                if (_promotionDao.FindByPromoCode(promoCode.Code) != null)
                {
                    throw new Exception("A promotion with this code already exists");
                }

                var promotionId = Guid.NewGuid();
                promoCode.Id = promotionId;

                var createPromotionCommand = new CreatePromotion
                {
                    PromoId                 = promotionId,
                    Name                    = promoCode.Name,
                    Description             = promoCode.Description,
                    StartDate               = promoCode.StartDate,
                    EndDate                 = promoCode.EndDate,
                    DaysOfWeek              = promoCode.DaysOfWeek,
                    StartTime               = promoCode.StartTime,
                    EndTime                 = promoCode.EndTime,
                    AppliesToCurrentBooking = promoCode.AppliesToCurrentBooking,
                    AppliesToFutureBooking  = promoCode.AppliesToFutureBooking,
                    DiscountValue           = promoCode.DiscountValue,
                    DiscountType            = promoCode.DiscountType,
                    Code                    = promoCode.Code,
                    TriggerSettings         = promoCode.TriggerSettings
                };

                if (promoCode.TriggerSettings.Type == PromotionTriggerTypes.NoTrigger)
                {
                    createPromotionCommand.PublishedStartDate = promoCode.PublishedStartDate;
                    createPromotionCommand.PublishedEndDate   = promoCode.PublishedEndDate;
                }
                else
                {
                    // Trigger promotions are always published (but user will only see them when whitelisted)
                    createPromotionCommand.PublishedStartDate = SqlDateTime.MinValue.Value;
                    createPromotionCommand.PublishedEndDate   = SqlDateTime.MaxValue.Value;
                }

                if (promoCode.TriggerSettings.Type != PromotionTriggerTypes.CustomerSupport)
                {
                    // User and system usage is unlimited for support promotion. The whitelist will determine if a user can use it.
                    createPromotionCommand.MaxUsage        = promoCode.MaxUsage;
                    createPromotionCommand.MaxUsagePerUser = promoCode.MaxUsagePerUser;
                }

                _commandBus.Send(createPromotionCommand);

                TempData["Info"] = string.Format("Promotion \"{0}\" created", promoCode.Name);

                var promotions = _promotionDao.GetAll().Select(x => new PromoCodeModel(x)).ToList();
                promotions.Add(promoCode);
                var orderedPromotions = promotions.OrderBy(p => p.Name);

                TempData["Model"] = orderedPromotions;

                return(RedirectToAction("Index", orderedPromotions));
            }
            catch (Exception ex)
            {
                ViewBag.Error = ex.Message;
                return(View(promoCode));
            }
        }