Ejemplo n.º 1
0
 private async void MakeOrder()
 {
     //using (var entities = new MobilekEntities())
     {
         OrderDTO order = new OrderDTO()
         {
             customerId = TheCustomer.Id,
             startDate = StartTime,
             endDate = EndTime,
             returnStationId = EndingStation.Id,
             Cars = SelectedCars
         };
         var service =new Services.WorkerDTOService(TheCustomer.userName,TheCustomer.password);
         var wor = await service.Get();
         var worker = wor.FirstOrDefault();
         if (worker!=null)
         {
             order.workerId = worker.id;
             //entities.Orders.Add(order);
             //entities.SaveChanges();
             var orderService = new Services.OrderDTOService(TheCustomer.userName, TheCustomer.password);
             await orderService.Post(order);
         }
     }
     GetOrders();
 }
Ejemplo n.º 2
0
        public ActionResult MakeOrder(MakeOrderModel model)
        {
            string msg = "";
            if (ModelState.IsValid)
            {
                try{
                    var cust = Task.Run(() => _customerService.Get(User.Identity.Name)).Result;
                    StationDTO station = Task.Run(() => _stationService.Get(model.stationItem)).Result;
                    List<CarDTO> cars = new List<CarDTO>();
                    foreach (int i in model.carItems)
                    {
                        cars.Add(Task.Run(() => _carService.Get(i)).Result);
                    }
                    OrderDTO order = new OrderDTO()
                    {
                        customerId = cust.Id,
                        endDate = model.endingDate,
                        startDate = model.startingDate,
                        returnStationId = station.Id,
                        isFinished = (model.endingDate<DateTime.Now),
                        workerId = 1,
                        Cars = cars
                    };
                    var result = Task.Run(() => _orderService.Post(order)).Result;
                }catch(Exception e){
                    msg = "Error occured:" + e.Message;
                }
            }
            else
            {
                msg = "Oder submission not successfull";
            }
            if (msg == "")
            {

            }
            else
            {
                ModelState.AddModelError("", msg);
            }

            List<SelectListItem> carList = Task.Run(() => _carService.Get()).Result
                .Select(s => new SelectListItem()
                {
                    Value = s.Id.ToString(),
                    Text = s.brand + " " + s.model

                }).ToList();
            ViewBag.cars = carList;

            IEnumerable<SelectListItem> items = Task.Run(() => _stationService.Get()).Result.Select(c => new SelectListItem
            {
                Value = c.Id.ToString(),
                Text = c.street + " " + c.streetNumer
            });
            ViewBag.Stationss = items.ToList();
            return View();
        }
Ejemplo n.º 3
0
 public async Task<OrderDTO> Post(OrderDTO item)
 {
     return await this.Post<OrderDTO, OrderDTO>("POST", item);
 }
Ejemplo n.º 4
0
 public void Add(OrderDTO item)
 {
     entities.Orders.Add(Mapper.Map<Order>(item));
     entities.SaveChanges();
 }