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 void DeleteCurrentExhibition(int exhId) { CurrentExhibition exh = _unitOfWork.CurrentExhibitionRepository.Get(exhId); if (exh == null) { throw new KeyNotFoundException(); } _unitOfWork.CurrentExhibitionRepository.Delete(exhId); _unitOfWork.Save(); }
public void DeleteItem(int itemId, int curExId) { int quantity = (int)_unitOfWork.TicketsInCartRepository.Get(itemId).Quantity; CurrentExhibition ceEntity = _unitOfWork.CurrentExhibitionRepository.Get(curExId); ceEntity.maxTicketQuantity += quantity; _unitOfWork.CurrentExhibitionRepository.Update(ceEntity); _unitOfWork.TicketsInCartRepository.Delete(itemId); _unitOfWork.Save(); }
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(); }
public void RemoveTicketFromCart(int itemId, int curExhId) { TicketsInCart itemEntity = _unitOfWork.TicketsInCartRepository.Get(itemId); CurrentExhibition exhibitionEntity = _unitOfWork.CurrentExhibitionRepository.Get(curExhId); if (itemEntity.Quantity > 1) { itemEntity.Quantity--; itemEntity.TotalPrice = _unitOfWork.ExhibitionRepository.Get(exhibitionEntity.IdExh).Price *itemEntity.Quantity; _unitOfWork.TicketsInCartRepository.Update(itemEntity); } else if (itemEntity.Quantity == 1) { _unitOfWork.TicketsInCartRepository.Delete(itemEntity.Id); } CurrentExhibition ceEntity = _unitOfWork.CurrentExhibitionRepository.Get(curExhId); ceEntity.maxTicketQuantity++; _unitOfWork.CurrentExhibitionRepository.Update(ceEntity); _unitOfWork.Save(); }