Пример #1
0
        public IHttpActionResult GetSpecificCustomerLastTransaction(string id)
        {
            try
            {
                if (Global.CheckAccessKey(Global.GetAccessKeyFromHeader(Request)))
                {
                    var guidCustomerId  = Guid.Parse(id);
                    var lastTransaction = TransactionDal.GetCustomerTransactionHistory(db, guidCustomerId).FirstOrDefault();
                    var customerPoints  = db.Users.SingleOrDefault(x => x.Id == id).Points;

                    return(Ok(new
                    {
                        lastTransaction = lastTransaction == null ? new TransactionDto() : lastTransaction,
                        customerPoints
                    }));
                }
                else
                {
                    return(BadRequest(Global.Message_WrongAccessKey));
                }
            }
            catch (AccessViolationException)
            {
                return(BadRequest(Global.Message_NoAccessKey));
            }
            catch (Exception)
            {
                return(BadRequest(Global.Message_ErrorMessage));
            }
        }
Пример #2
0
        public ActionResult Create()
        {
            ViewBag.UserId = User.Identity.GetUserId();

            return(View(new TransactionDto
            {
                CustomerId = null,
                CouponId = null,
                TransactionTypeOptions = TransactionDal.GetTransactionTypes()
            }));
        }
Пример #3
0
        public ActionResult GetCustomerData(string userId)
        {
            try
            {
                var targetCustomer  = db.Users.SingleOrDefault(x => x.Id == userId);
                var customerDataDto = Mapper.Map <ApplicationUser, CustomerDataDto>(targetCustomer);
                customerDataDto.Picture             = customerDataDto.Picture ?? "/Media/avatar-placeholder.png";
                customerDataDto.TransactionHistory  = new List <TransactionDto>();
                customerDataDto.PurchaseableCoupons = new List <CouponDto>();

                if (Global.CheckIfUserInRole(
                        Global.GetUserRole(targetCustomer.Id), new List <string> {
                    RoleList.Customer, RoleList.Groomer, RoleList.CSS
                }))
                {
                    var guidCustomerId      = Guid.Parse(targetCustomer.Id);
                    var purchaseableCoupons = db.Coupons.Where(x
                                                               => x.IsActive &&
                                                               x.Purchased < x.Amount &&
                                                               x.PointPrice <= customerDataDto.Points)
                                              .OrderBy(x => x.PointPrice)
                                              .ToList();

                    customerDataDto.TransactionHistory = TransactionDal.GetCustomerTransactionHistory(db, guidCustomerId);

                    foreach (var coupon in purchaseableCoupons)
                    {
                        var couponDto = Mapper.Map <Coupon, CouponDto>(coupon);
                        couponDto.CouponValue     = CouponDal.GetCouponValue(coupon);
                        couponDto.CouponTypeValue = coupon.CouponType.ToString();
                        customerDataDto.PurchaseableCoupons.Add(couponDto);
                    }

                    return(Json(new { success = customerDataDto }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    throw new NullReferenceException();
                }
            }
            catch (NullReferenceException)
            {
                return(Json(new { error = "null" }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                return(Json(new { error = "error" }, JsonRequestBehavior.AllowGet));
            }
        }
Пример #4
0
        public ActionResult Create(TransactionDto transactionDto)
        {
            if (ModelState.IsValid)
            {
                var userId      = User.Identity.GetUserId();
                var transaction = Mapper.Map <TransactionDto, Transaction>(transactionDto);
                transaction.NewCreatedData(userId);
                transaction.EarnedPoint = TransactionDal.CalculateEarnedPointByTransanction(db, transaction.Total);
                CouponDal.AddCouponPurchaseCount(db, transaction.CouponId);
                TransactionDal.DeductCustomerPointByCoupon(db, transaction.CustomerId.ToString(), transaction.CouponId);
                TransactionDal.AddPointToCustomer(db, transaction.CustomerId.ToString(), transaction.EarnedPoint);
                db.Transactions.Add(transaction);
                db.SaveChanges();
                return(RedirectToAction("Create"));
            }

            ViewBag.UserId = User.Identity.GetUserId(); return(View(transactionDto));
        }
Пример #5
0
        public IHttpActionResult GetSpecificCustomerTransactionHistory(string id)
        {
            try
            {
                if (Global.CheckAccessKey(Global.GetAccessKeyFromHeader(Request)))
                {
                    var guidCustomerId = Guid.Parse(id);

                    return(Ok(TransactionDal.GetCustomerTransactionHistory(db, guidCustomerId)));
                }
                else
                {
                    return(BadRequest(Global.Message_WrongAccessKey));
                }
            }
            catch (AccessViolationException)
            {
                return(BadRequest(Global.Message_NoAccessKey));
            }
            catch (Exception)
            {
                return(BadRequest(Global.Message_ErrorMessage));
            }
        }
Пример #6
0
 public static Boolean ajoutTransaction(int cdTransfert, String detail, String codeErreur, String etat, DateTime date)
 {
     return(TransactionDal.InsertTransaction(cdTransfert, detail, codeErreur, etat, date));
 }
Пример #7
0
 public static String getMaxTransactTRFT(int cdTRFT)
 {
     return(TransactionDal.getMaxTransactTRFT(cdTRFT));
 }
Пример #8
0
 public static IList <Transaction> getTransactions(int cdTRFT)
 {
     return(TransactionDal.getTransactions(cdTRFT));
 }
Пример #9
0
 public static String getDate(int cdTransaction)
 {
     return(TransactionDal.getDate(cdTransaction));
 }
Пример #10
0
 public static String getCodeErreur(int cdTransaction)
 {
     return(TransactionDal.getCodeErreur(cdTransaction));
 }
Пример #11
0
 public static int getcdTransactionmax()
 {
     return(TransactionDal.getCdTransactionmax());
 }