public ActionResult ReservePhone(int phoneId, int quantity) { _reservationService.ReservationChecker(); var phone = _phoneRepository.GetPhone(phoneId); if (phone.Amount < quantity || quantity <= 0) { return(RedirectToAction("Eroor")); } var parametrs = new PriceStrategyParametersDTO(); parametrs.PhoneId = phoneId; parametrs.Quantity = quantity; var reservation = _reservationService.Reserve(phoneId, quantity); var model = new ReservationViewModel() { Reservation = reservation, Phone = phone, OrderItem = _priceCalculationStrategy.CalculatePrice(parametrs), Quantity = quantity }; return(View(model)); }
public List <OrderItem> CalculatePrice(PriceStrategyParametersDTO parametrs) { var components = new List <OrderItem>(); var phone = _phoneRepository.GetPhone(parametrs.PhoneId); var phoneComponent = new OrderItem(); phoneComponent.Price = phone.Price * parametrs.Quantity; components.Add(phoneComponent); return(components); }
public Order CreateOrder(OrderParametersDTO parametersDTO) { var res = _resRepo.Get(parametersDTO.ReservationId); if (res.OrderId != null) { throw new InvalidOperationException("Phone has been already issued to this reservation, unable to create another one"); } var phone = _phoneRepository.GetPhone(res.ReservedItem.PhoneId); var newOrder = new Order() { ReservationId = res.Id, OrderDate = DateTime.Now, Name = parametersDTO.Name, Address = parametersDTO.Address, Email = parametersDTO.Email, City = parametersDTO.City, Status = OrderStatusEnum.Active, OrderItems = new List <OrderItem>() }; var priceParametrs = new PriceStrategyParametersDTO(); priceParametrs.PhoneId = phone.Id; priceParametrs.Quantity = parametersDTO.Quantity; newOrder.OrderItems = _priceStr.CalculatePrice(priceParametrs); res.OrderId = newOrder.Id; _resRepo.Update(res); _orderRepository.Create(newOrder); return(newOrder); }