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 GetFilterableTransactionHistory([FromUri] string startDate, string endDate) { var startFilterDate = DateTime.MinValue; var endFilterDate = DateTime.MaxValue; var listToReturn = new List <TransactionDto>(); if (startDate != "day-month-year") { startFilterDate = Global.ParseStringToDate(startDate); } if (endDate != "day-month-year") { endFilterDate = Global.ParseStringToDate(endDate).AddDays(1); } var transactionHistories = db.Transactions .Where(x => x.IsActive && x.CreatedDate >= startFilterDate && x.CreatedDate < endFilterDate) .OrderByDescending(x => x.CreatedDate) .ToList(); foreach (var history in transactionHistories) { var historyDto = Mapper.Map <Transaction, TransactionDto>(history); if (historyDto.CouponId != null) { historyDto.CouponValue = CouponDal.GetCouponValue(db.Coupons.SingleOrDefault(x => x.Id == historyDto.CouponId)); } else { historyDto.CouponValue = "-"; } historyDto.CreatedDate = Global.DateToString(history.CreatedDate); historyDto.CustomerName = Global.GetUserNameById(history.CustomerId.ToString()); listToReturn.Add(historyDto); } return(Ok(listToReturn)); }