Beispiel #1
0
 public IActionResult PromocodeDetail(GetPromoCodeDetailModel promoCodeDetailModel)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var promocodeDetail = iPromoCode.GetPromocodeDetail(DBHelper.ParseInt64(promoCodeDetailModel.promoCodeId));
             if (promocodeDetail != null)
             {
                 PromoCodeDataListModel promoCodeListModel = PromoCodeHelper.BindPromoCodeListModel(promocodeDetail);
                 return(Ok(ResponseHelper.Success(promoCodeListModel)));
             }
             else
             {
                 return(Ok(ResponseHelper.Error(MessageConstants.DataNotFound)));
             }
         }
         else
         {
             return(Ok(ResponseHelper.Error(MessageConstants.DataNotFound)));
         }
     }
     catch (Exception ex)
     {
         LogHelper.ExceptionLog(ex.Message + "  :::::  " + ex.StackTrace);
         return(Ok(ResponseHelper.Error(ex.Message)));
     }
 }
Beispiel #2
0
 public IActionResult UpdatePromoCode(AddPromoCodeModel addPromoCodeModel)
 {
     try
     {
         if (ModelState.IsValid)
         {
             PromoCode promoCodeModel = PromoCodeHelper.BindPromoCode(addPromoCodeModel);
             long      promoCodeId    = iPromoCode.UpdatePromocode(promoCodeModel);
             if (promoCodeId > 0)
             {
                 return(Ok(ResponseHelper.Success(MessageConstants.PromocodeUpdated)));
             }
             else if (promoCodeId == ReturnCode.AlreadyExist.GetHashCode())
             {
                 return(Ok(ResponseHelper.Error(MessageConstants.TryDifferentCode)));
             }
             else
             {
                 return(Ok(ResponseHelper.Error(MessageConstants.PromocodeNotUpdated)));
             }
         }
         else
         {
             return(Ok(ResponseHelper.Error(MessageConstants.CompulsoryData)));
         }
     }
     catch (Exception ex)
     {
         LogHelper.ExceptionLog(ex.Message + "  :::::  " + ex.StackTrace);
         return(Ok(ResponseHelper.Error(ex.Message)));
     }
 }
Beispiel #3
0
 public IActionResult AddPromoCode(AddPromoCodeModel addPromoCodeModel)
 {
     try
     {
         if (ModelState.IsValid)
         {
             PromoCode promoCodeModel = PromoCodeHelper.BindPromoCode(addPromoCodeModel);
             if (!string.IsNullOrWhiteSpace(addPromoCodeModel.PromoCodeId) && DBHelper.ParseInt64(addPromoCodeModel.PromoCodeId) <= 0)
             {
                 promoCodeModel.CreatedOn = DateTime.Now;
                 long promoCodeId = iPromoCode.AddPromocode(promoCodeModel);
                 if (promoCodeId > 0)
                 {
                     return(Ok(ResponseHelper.Success(MessageConstants.PromocodeAdded)));
                 }
                 else if (promoCodeId == ReturnCode.AlreadyExist.GetHashCode())
                 {
                     return(Ok(ResponseHelper.Error(MessageConstants.TryDifferentCode)));
                 }
                 else
                 {
                     return(Ok(ResponseHelper.Error(MessageConstants.PromocodeNotAdded)));
                 }
             }
             else
             {
                 promoCodeModel.ModifiedOn = DateTime.Now;
                 long promoCodeId = iPromoCode.UpdatePromocode(promoCodeModel);
                 if (promoCodeId > 0)
                 {
                     return(Ok(ResponseHelper.Success(MessageConstants.PromocodeUpdated)));
                 }
                 else if (promoCodeId == ReturnCode.AlreadyExist.GetHashCode())
                 {
                     return(Ok(ResponseHelper.Error(MessageConstants.TryDifferentCode)));
                 }
                 else
                 {
                     return(Ok(ResponseHelper.Error(MessageConstants.PromocodeNotUpdated)));
                 }
             }
         }
         else
         {
             return(Ok(ResponseHelper.Error(MessageConstants.CompulsoryData)));
         }
     }
     catch (Exception ex)
     {
         LogHelper.ExceptionLog(ex.Message + "  :::::  " + ex.StackTrace);
         return(Ok(ResponseHelper.Error(ex.Message)));
     }
 }
Beispiel #4
0
        public async Task <PromoCode> GeneratePromoCode(NewPromoRequest newPromoCode)
        {
            var promoCode = new PromoCode
            {
                Id         = Guid.NewGuid(),
                ExpiryDate = newPromoCode.ExpiryDate,
                Value      = newPromoCode.Value,
                Code       = string.IsNullOrEmpty(newPromoCode.Code)
                    ? PromoCodeHelper.RandomString(PromoCodeConstant.PromoCodeLength, true)
                    : newPromoCode.Code
            };

            await _context.PromoCodes.InsertOneAsync(promoCode);

            return(promoCode);
        }
Beispiel #5
0
        public IActionResult PromocodeList(SearchPaginationListModel searchModel)
        {
            try
            {
                if (searchModel.pageNo <= 0)
                {
                    searchModel.pageNo = 1;
                }
                var promoCodeList = iPromoCode.GetPromocodeList(searchModel.searchString);
                if (promoCodeList != null)
                {
                    PromoCodeListModel promoCodeListModel   = new PromoCodeListModel();
                    List <PromoCode>   promoCodePagedresult = new List <PromoCode>();
                    promoCodePagedresult = promoCodeList.OrderByDescending(x => x.PromoCodeId).ToPagedList(searchModel.pageNo, searchModel.limit).ToList();

                    #region Sorting
                    if (searchModel.column.ToLower().Equals(DBHelper.ParseString(SortingPromocodeColumnName.promocodeid)) && searchModel.direction.ToLower().Equals(DBHelper.ParseString(SortingDirectionType.asc)))
                    {
                        promoCodePagedresult = promoCodeList.OrderBy(x => x.PromoCodeId).ToPagedList(searchModel.pageNo, searchModel.limit).ToList();
                    }
                    else if (searchModel.column.ToLower().Equals(DBHelper.ParseString(SortingPromocodeColumnName.promocodeid)) && searchModel.direction.ToLower().Equals(DBHelper.ParseString(SortingDirectionType.desc)))
                    {
                        promoCodePagedresult = promoCodeList.OrderByDescending(x => x.PromoCodeId).ToPagedList(searchModel.pageNo, searchModel.limit).ToList();
                    }
                    else if (searchModel.column.ToLower().Equals(DBHelper.ParseString(SortingPromocodeColumnName.name)) && searchModel.direction.ToLower().Equals(DBHelper.ParseString(SortingDirectionType.asc)))
                    {
                        promoCodePagedresult = promoCodeList.OrderBy(x => x.Name).ToPagedList(searchModel.pageNo, searchModel.limit).ToList();
                    }
                    else if (searchModel.column.ToLower().Equals(DBHelper.ParseString(SortingPromocodeColumnName.name)) && searchModel.direction.ToLower().Equals(DBHelper.ParseString(SortingDirectionType.desc)))
                    {
                        promoCodePagedresult = promoCodeList.OrderByDescending(x => x.Name).ToPagedList(searchModel.pageNo, searchModel.limit).ToList();
                    }
                    else if (searchModel.column.ToLower().Equals(DBHelper.ParseString(SortingPromocodeColumnName.code)) && searchModel.direction.ToLower().Equals(DBHelper.ParseString(SortingDirectionType.asc)))
                    {
                        promoCodePagedresult = promoCodeList.OrderBy(x => x.Code).ToPagedList(searchModel.pageNo, searchModel.limit).ToList();
                    }
                    else if (searchModel.column.ToLower().Equals(DBHelper.ParseString(SortingPromocodeColumnName.code)) && searchModel.direction.ToLower().Equals(DBHelper.ParseString(SortingDirectionType.desc)))
                    {
                        promoCodePagedresult = promoCodeList.OrderByDescending(x => x.Code).ToPagedList(searchModel.pageNo, searchModel.limit).ToList();
                    }
                    else if (searchModel.column.ToLower().Equals(DBHelper.ParseString(SortingPromocodeColumnName.startdate)) && searchModel.direction.ToLower().Equals(DBHelper.ParseString(SortingDirectionType.asc)))
                    {
                        promoCodePagedresult = promoCodeList.OrderBy(x => x.StartDate).ToPagedList(searchModel.pageNo, searchModel.limit).ToList();
                    }
                    else if (searchModel.column.ToLower().Equals(DBHelper.ParseString(SortingPromocodeColumnName.startdate)) && searchModel.direction.ToLower().Equals(DBHelper.ParseString(SortingDirectionType.desc)))
                    {
                        promoCodePagedresult = promoCodeList.OrderByDescending(x => x.StartDate).ToPagedList(searchModel.pageNo, searchModel.limit).ToList();
                    }
                    else if (searchModel.column.ToLower().Equals(DBHelper.ParseString(SortingPromocodeColumnName.expirydate)) && searchModel.direction.ToLower().Equals(DBHelper.ParseString(SortingDirectionType.asc)))
                    {
                        promoCodePagedresult = promoCodeList.OrderBy(x => x.ExpiryDate).ToPagedList(searchModel.pageNo, searchModel.limit).ToList();
                    }
                    else if (searchModel.column.ToLower().Equals(DBHelper.ParseString(SortingPromocodeColumnName.expirydate)) && searchModel.direction.ToLower().Equals(DBHelper.ParseString(SortingDirectionType.desc)))
                    {
                        promoCodePagedresult = promoCodeList.OrderByDescending(x => x.ExpiryDate).ToPagedList(searchModel.pageNo, searchModel.limit).ToList();
                    }
                    else if (searchModel.column.ToLower().Equals(DBHelper.ParseString(SortingPromocodeColumnName.discount)) && searchModel.direction.ToLower().Equals(DBHelper.ParseString(SortingDirectionType.asc)))
                    {
                        promoCodePagedresult = promoCodeList.OrderBy(x => x.Amount).ThenBy(x => x.Percentage).ToPagedList(searchModel.pageNo, searchModel.limit).ToList();
                    }
                    else if (searchModel.column.ToLower().Equals(DBHelper.ParseString(SortingPromocodeColumnName.discount)) && searchModel.direction.ToLower().Equals(DBHelper.ParseString(SortingDirectionType.desc)))
                    {
                        promoCodePagedresult = promoCodeList.OrderByDescending(x => x.Amount).ThenByDescending(x => x.Percentage).ToPagedList(searchModel.pageNo, searchModel.limit).ToList();
                    }
                    else
                    {
                        promoCodePagedresult = promoCodeList.OrderBy(x => x.PromoCodeId).ToPagedList(searchModel.pageNo, searchModel.limit).ToList();
                    }
                    #endregion

                    List <PromoCodeDataListModel> promoCodeDataListModel = PromoCodeHelper.BindPromoCodeListModel(promoCodePagedresult);
                    //promoCodeListModel.Total =DBHelper.ParseString(iPromoCode.GetTotalPromocodeCount());
                    promoCodeListModel.Total = DBHelper.ParseString(promoCodeList.Count);
                    promoCodeListModel.Items = promoCodeDataListModel;
                    return(Ok(ResponseHelper.Success(promoCodeListModel)));
                }
                else
                {
                    return(Ok(ResponseHelper.Error(MessageConstants.DataNotFound)));
                }
            }
            catch (Exception ex)
            {
                LogHelper.ExceptionLog(ex.Message + "  :::::  " + ex.StackTrace);
                return(Ok(ResponseHelper.Error(ex.Message)));
            }
        }