public IEnumerable <Voucher> GetVouchers() { IEnumerable <Voucher> ap = Vou_repo.GetAll(a => a.VoucherDetails); ap = ap.OrderByDescending(a => a.VoucherId); return(ap); }
public IActionResult Get() { StringValues hearderValues; var firstValue = string.Empty; if (Request.Headers.TryGetValue("id", out hearderValues)) { firstValue = hearderValues.FirstOrDefault(); } long id = Convert.ToInt64(firstValue); var item = _repository.Find(id); if (item == null) { return(NotFound()); } #region Interactions List // Rate list for the user that he commented for this product List <Interaction> InteractionList = new List <Interaction>(); var InteractionQuery = from interaction in _interactionRepository.GetAll() where interaction.UserId == item.UserId select interaction; foreach (var interaction in InteractionQuery) { Interaction UserRate = new Interaction(); UserRate = interaction; var InteractedProduct = _productRepository.Find(interaction.ProductId); UserRate.Product = InteractedProduct; UserRate.User = null; InteractionList.Add(UserRate); } item.Interactions = InteractionList; #endregion #region Vouchers List // Vouchers List var Query = from voucher in _voucherRepository.GetAll() where voucher.UserId == item.UserId select voucher; List <Voucher> VoucherList = new List <Voucher>(); foreach (var voucher in Query) { Voucher v = new Voucher(); v = voucher; VoucherList.Add(v); } item.Vouchers = VoucherList; // End Vouchers List #endregion // Unset variables that are unused InteractionList = null; InteractionQuery = null; VoucherList = null; Query = null; return(new ObjectResult(item)); }
public void GetVoucherList(AddEditVoucherViewModel viewModel) { viewModel.VoucherEntries.Clear(); foreach (var voucher in VoucherRepository.GetAll()) { viewModel.VoucherEntries.Add(voucher.VoucherNo); } }
public bool Create(VoucherCreateRequest entity) { string description = entity.Description; int quantity = entity.Quantity; int available = quantity; string code = entity.Code; DateTime beginDate = entity.BeginDate; DateTime expiredDate = entity.ExpiredDate; int maxDiscount = entity.MaxDiscountAmount; int minRequiredAmount = entity.MinRequiredAmount; int percentDiscount = entity.PercentDiscount; int proId = entity.PromotionId; if (!util.ValidRangeLengthInput(description, 1, 250) || !util.ValidRangeLengthInput(code, 1, 20) || beginDate.CompareTo(expiredDate) == 1 || quantity < 0 || percentDiscount <= 0 || maxDiscount <= 0 || minRequiredAmount <= 0 ) { return(false); } Voucher existed = _vouRepo.GetAll().FirstOrDefault(e => e.Code.Trim().ToLower().Equals(code.Trim().ToLower())); if (existed != null) { return(false); } Voucher newEntity = new Voucher(); newEntity.Description = description; newEntity.Quantity = quantity; newEntity.Available = available; newEntity.Code = code; newEntity.BeginDate = beginDate; newEntity.ExpiredDate = expiredDate; newEntity.MinRequiredAmount = minRequiredAmount; newEntity.MaxDiscountAmount = maxDiscount; newEntity.PercentDiscount = percentDiscount; newEntity.PromotionId = proId; return(_vouRepo.Create(newEntity)); }
public async Task <IActionResult> GetAllVouchers() { try { var allVoucher = await _voucherRepository.GetAll(); return(Ok(allVoucher)); } catch (System.ArgumentNullException ex) { return(NotFound()); } catch (Exception e) { return(BadRequest()); } }
public IEnumerable <Voucher> GetAll() { List <Voucher> ListVoucher = new List <Voucher>(); foreach (Voucher VoucherOne in _repository.GetAll()) { Voucher NewVoucher = new Voucher(); NewVoucher = VoucherOne; Showroomer UpdatedUser = new Showroomer(); var OldUser = _showroomerRepository.Find(VoucherOne.UserId); UpdatedUser = OldUser; UpdatedUser.Vouchers = null; UpdatedUser.Showrooms = null; UpdatedUser.Orders = null; UpdatedUser.Interactions = null; NewVoucher.User = UpdatedUser; ListVoucher.Add(NewVoucher); } return(ListVoucher); }
public bool Create(ClaimedVoucherCreateRequest entity) { int userId = entity.UserId; int voucherId = entity.VoucherId; int available = entity.Available; Voucher voucher = _vouRepo.GetAll().FirstOrDefault(e => e.Id == voucherId); if (available <= 0 || available > voucher.Available) { return(false); } ClaimedVoucher existed = _claimedRepo.GetAll().FirstOrDefault(e => e.UserId == userId && e.VoucherId == voucherId); if (existed != null) { existed.Available += available; return(_claimedRepo.Update(existed)); } ClaimedVoucher newEntity = new ClaimedVoucher(); newEntity.Available = available; newEntity.ClaimedDate = DateTime.Now; newEntity.ExpiredDate = DateTime.Now.AddDays(30); newEntity.UserId = userId; newEntity.VoucherId = voucherId; bool success = _claimedRepo.Create(newEntity); //update voucher available if (success) { voucher.Available -= available; success = _vouRepo.Update(voucher); } return(success); }
public IEnumerable <Voucher> GetAlls() { return(_voucher.GetAll(null)); }
public IActionResult Get() { StringValues hearderValues; var firstValue = string.Empty; if (Request.Headers.TryGetValue("id", out hearderValues)) { firstValue = hearderValues.FirstOrDefault(); } long id = Convert.ToInt64(firstValue); var item = _repository.Find(id); if (item == null) { return(NotFound()); } #region Interactions List // Rate list for the user that he commented for this product List <Interaction> InteractionList = new List <Interaction>(); var InteractionQuery = from interaction in _interactionRepository.GetAll() where interaction.UserId == item.UserId select interaction; foreach (var interaction in InteractionQuery) { Interaction UserRate = new Interaction(); UserRate = interaction; UserRate.User = null; UserRate.Product = null; InteractionList.Add(UserRate); } item.Interactions = InteractionList; #endregion #region Vouchers List // Vouchers List var Query = from voucher in _voucherRepository.GetAll() where voucher.UserId == item.UserId select voucher; List <Voucher> VoucherList = new List <Voucher>(); foreach (var voucher in Query) { Voucher v = new Voucher(); v = voucher; v.User = null; VoucherList.Add(v); } item.Vouchers = VoucherList; // End Vouchers List #endregion #region Showrooms List // Rate list for the user that he commented for this product List <Showroom> ShowroomList = new List <Showroom>(); var ShowroomQuery = from showroom in _showroomRepository.GetAll() where showroom.ShowroomerId == item.UserId select showroom; foreach (var showroom in ShowroomQuery) { Showroom UserShowroom = new Showroom(); UserShowroom = showroom; // Product that this user accept to be showroom var ProductQuery = from product in _productRepository.GetAll() where product.ProductId == showroom.ProductId select product; if (ProductQuery == null) { UserShowroom.Product = null; } else { Product NewProduct = new Product(); var OldProduct = ProductQuery.First(); NewProduct = OldProduct; NewProduct.Images = null; NewProduct.Interactions = null; NewProduct.Orders = null; NewProduct.Showrooms = null; UserShowroom.Product = NewProduct; } UserShowroom.Showroomer = null; ShowroomList.Add(UserShowroom); } item.Showrooms = ShowroomList; #endregion // Unset variables that are unused InteractionList = null; InteractionQuery = null; VoucherList = null; Query = null; ShowroomList = null; ShowroomQuery = null; return(new ObjectResult(item)); }
public async Task <ActionResult <List <Voucher> > > GetAll() { return(await _voucherRepository.GetAll()); }