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)); } }
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)); } }
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)); } }