public async Task <IActionResult> PutDriver([FromRoute] int id, [FromBody] Driver driver)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != driver.Id)
            {
                return(BadRequest());
            }

            _context.Entry(driver).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DriverExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> Create([Bind("ID,dropOffLat,pdropOffLat,pickUpLat,pickUpLon")] TaxiTrip taxiTrip)
        {
            if (ModelState.IsValid)
            {
                _context.Add(taxiTrip);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(taxiTrip));
        }
Exemple #3
0
 public async Task <T> Add(T entity)
 {
     _taxiContext.Set <T>().Add(entity);
     try
     {
         await _taxiContext.SaveChangesAsync();
     }
     catch
     {
         return(null);
     }
     return(entity);
 }
Exemple #4
0
        public async Task <Order> CreateOrder(Order order)
        {
            var newOrder = new Order
            {
                StartPoint = order.StartPoint,
                EndPoint   = order.EndPoint,
                Price      = order.Price
            };

            _context.Orders.Add(newOrder);
            await _context.SaveChangesAsync();

            return(newOrder);
        }
Exemple #5
0
        public async Task <IActionResult> Create([Bind("OrderID,ClientID,DriverID,CarID,DepPlace,DestPlace,Time")] Order order)
        {
            if (ModelState.IsValid)
            {
                _context.Add(order);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            DriversDropDownList(order.DriverID);
            ClientsDropDownList(order.ClientID);
            CarsDropDownList(order.CarID);
            return(View(order));
        }
Exemple #6
0
        public async Task <IActionResult> ChangeState([FromBody] ChangestateViewModel model)
        {
            try
            {
                #region بررسی اعتبار درخواست کننده
                var taxtiCab = await _context.TaxiServices.Undelited().FirstOrDefaultAsync(c => c.Id == model.TaxiCabId);

                if (taxtiCab == null || taxtiCab.DriverId != model.DriverId)
                {
                    await _logger.LogAsync(HttpContext, $"{nameof(taxtiCab)} Is NULL");

                    return(Ok(new ResultContract <bool>()
                    {
                        statuse = false, Data = false, message = "مشکلی بوجود آمد"
                    }));
                }
                #endregion

                var Service = await _context.ServiceRequsets.Include(c => c.StudentParent).FirstOrDefaultAsync(c => c.Id == model.RequseteId);

                if (Service == null)
                {
                    await _logger.LogAsync(HttpContext, $"{nameof(Service)} Is NULL");

                    return(Ok(new ResultContract <bool>()
                    {
                        statuse = false, Data = false, message = "مشکلی بوجود آمد"
                    }));
                }

                Service.NotifState = model.NotifState;
                _context.Update(Service);
                await _context.SaveChangesAsync();

                var    number = Service.StudentParent.PhoneNubmber;
                string token  = Service.Id;
                if (model.NotifState == NotifState.GetOn)
                {
                    await _notify.SendNotifyWithTemplateAsync(number, token, MessageTemplate.Bistrogetoff);
                }
                else
                {
                    await _notify.SendNotifyWithTemplateAsync(number, token, MessageTemplate.Bistogeton);
                }

                return(Ok(new ResultContract <bool>()
                {
                    statuse = true, Data = true
                }));
            }
            catch (Exception ex)
            {
                await _logger.LogAsync(HttpContext, ex);

                return(Ok(new ResultContract <bool>()
                {
                    statuse = false, Data = false, message = "مشکلی بوجود آمد"
                }));
            }
        }
Exemple #7
0
        public async Task <IActionResult> RemovePassenger(string Id, string PassngerId)
        {
            var TaxiService = await _context.TaxiServices.Undelited()
                              .Include(t => t.Driver)
                              .Include(c => c.Passnegers)
                              .FirstOrDefaultAsync(c => c.Id == Id & c.Driver.ContractorId == User.GetContractor().Id);

            if (TaxiService == null)
            {
                return(NotFound());
            }

            var passnger = TaxiService.Passnegers.FirstOrDefault(c => c.Id == PassngerId);

            if (passnger == null)
            {
                ViewBag.msg = "مسافری با این مشخصات  یافت نشد";
                return(View(nameof(Passengers), new { id = Id }));
            }

            passnger.TaxiServiceId         = null;
            _context.Entry(passnger).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Passengers), new { id = Id }));
        }
        public async Task <Order> CreateOrder(Order order)
        {
            //Verify that Customer have no order where order have not complete
            var _order = _context.Orders.Where(e => e.CustomerId == order.CustomerId)
                         .Where(e => e.IsCancel == false)
                         .SingleOrDefault(e => e.Status == false);

            if (_order != null)
            {
                throw new AppException("Please complete or cancel your current booking first!!!");
            }

            int _pickup  = (int)ProvinceList.Province[order.PickupLocation];
            int _return  = (int)ProvinceList.Province[order.ReturnLocation];
            int distance = Math.Abs(_pickup - _return);

            order.Price = distance * order.Reservations * VALUE;

            if (order.Reservations <= _context.Schedules.SingleOrDefault(e => e.DriverId == order.DriverId).AvailablableSlot)
            {
                _context.Schedules.SingleOrDefault(e => e.DriverId == order.DriverId).AvailablableSlot -= order.Reservations;
            }
            else
            {
                throw new AppException("Error! Reservations > AvailableSlot");
            }
            order.Created = DateTime.Now;
            //save notify
            var _notifi      = new Notify();
            var _userId      = _context.Drivers.Find(order.DriverId).UserId;
            var CustomerName = _context.Customers.Find(order.CustomerId).User.Name;

            _notifi.UserId  = _userId;
            _notifi.Content = $"Có Order mới: Customer: {CustomerName}; Nơi đón: {order.PickupLocation}; Nơi đến: {order.ReturnLocation}; Số ghế: {order.Reservations}";
            _context.Notifies.Add(_notifi);
            await _context.Orders.AddAsync(order);

            await _context.SaveChangesAsync();

            //send notification to driver

            return(order);
        }
Exemple #9
0
        public async Task <IActionResult> Create([Bind("CarNumber,CarClass,CarSize")] Car car)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(car);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (DbUpdateException /* ex */)
            {
                //Log the error (uncomment ex variable name and write a log.
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
            }
            return(View(car));
        }
Exemple #10
0
        public async Task <IActionResult> Reservation(int carId, double phone, DateTime time)
        {
            var car = await _context.Cars.FirstOrDefaultAsync(c => c.Id == carId);

            if (car == null)
            {
                NotFound("Car not exist");
            }

            if (car.IsReserved)
            {
                BadRequest("Car already reserved");
            }

            car.IsReserved        = true;
            car.ClientPhoneNumber = phone;
            car.TimeReservation   = time;

            _context.Cars.Update(car);
            await _context.SaveChangesAsync();

            return(Ok());
        }
Exemple #11
0
        public async Task CompleteOrder(int orderId)
        {
            var order = await _context.Orders.FindAsync(orderId);

            if (order.IsCancel == true)
            {
                throw new AppException("Error! Order have been cancel.");
            }
            if (order.Status == false)
            {
                order.Status = true;
                order.Driver.Schedule.AvailablableSlot += order.Reservations;
                _context.Orders.Update(order);
                await _context.SaveChangesAsync();
            }
        }