public void AddCurrentExhibition(int idExh, int idEmp, int idPlace, DateTime begin, DateTime end) { CurrentExhibition itemEntity = _unitOfWork.CurrentExhibitionRepository.GetAll().ToList().Find( i => i.IdExh == idExh && i.IdExhPlace == idPlace); if (itemEntity != null) { throw new ArgumentException("This exhibition already exists! Find and edit it"); } else { CurrentExhibitionModel newItem = new CurrentExhibitionModel() { IdEmployee = idEmp, IdExh = idExh, IdExhPlace = idPlace, Exhibition = _mapper.Map <ExhibitionModel>(_unitOfWork.ExhibitionRepository.Get(idExh)), DateBegin = begin, DateEnd = end }; CurrentExhibition newItemEntity = _mapper.Map <CurrentExhibition>(newItem); _unitOfWork.CurrentExhibitionRepository.Add(newItemEntity); } _unitOfWork.Save(); }
public IActionResult AddTicketToCartByPlus(int curExhId) { CurrentExhibitionModel ce = _currExhService.GetCurExhById(curExhId); if (ce.MaxTicketQuantity >= 1) { _ticketService.AddTicketToCart(ce, 1, GetCartId().Result); } return(RedirectToAction("Cart", "Cart")); }
public IActionResult BuyTicket(int curExId, int quantity) { CurrentExhibitionModel visitedExh = _currExhService.GetCurExhById(curExId); if (quantity <= visitedExh.MaxTicketQuantity) { _ticketService.AddTicketToCart(visitedExh, quantity, GetCartId().Result); } return(RedirectToAction("Cart", "Cart", new { visitedExh.IdExh, curExId })); }
public SingleExh(ExhibitionModel exhibition, CurrentExhibitionModel CurrentExhibition, List <ExhibitedPictureModel> pictures, ExhibitPlaceModel place, CityModel city) { this.CurrentExhibition = CurrentExhibition; Exhibition = exhibition; this.CurrentExhibition.ExhibitPlace = place; this.CurrentExhibition.ExhibitPlace.City = city; if (CurrentExhibition.Tag == Status.future) { Message = $"looking forward to see you! \n Starting on {CurrentExhibition.DateBegin} " + $"\n You can still book tickets!"; Pictures = new List <ExhibitedPictureModel>(); } else { Message = Exhibition.Description; Pictures = pictures; } }
public void AddTicketToCart(CurrentExhibitionModel Exhibition, int quantity, string cartId) { TicketsInCart ticketincartEntity = _unitOfWork.TicketsInCartRepository.GetAll().ToList().Find( i => i.CartId == cartId && i.CurExhId == Exhibition.Id); var exh = _unitOfWork.ExhibitionRepository.Get(Exhibition.IdExh); if (ticketincartEntity != null) { ticketincartEntity.Quantity += quantity; ticketincartEntity.TotalPrice = exh.Price * ticketincartEntity.Quantity; _unitOfWork.TicketsInCartRepository.Update(ticketincartEntity); } else { if (Exhibition.MaxTicketQuantity > 0) { TicketInCartModel newItem = new TicketInCartModel() { CurExhId = Exhibition.Id, BuyDate = DateTime.Now, Quantity = quantity, CartId = cartId, TotalPrice = exh.Price * quantity }; TicketsInCart newItemEntity = _mapper.Map <TicketsInCart>(newItem); _unitOfWork.TicketsInCartRepository.Add(newItemEntity); _unitOfWork.Save(); } } CurrentExhibition ticketsForExh = _unitOfWork.CurrentExhibitionRepository.Get(Exhibition.Id); ticketsForExh.maxTicketQuantity -= quantity; _unitOfWork.CurrentExhibitionRepository.Update(ticketsForExh); _unitOfWork.Save(); }