Esempio n. 1
0
        public void DeleteDriver(int id)
        {
            var driver = _context.Drivers.Find(id);

            if (driver != null)
            {
                //delete related data
                var schedule = driver.Schedule;
                if (schedule != null)
                {
                    _context.Schedules.Remove(schedule);
                }
                var vehicle = driver.Vehicle;
                if (vehicle != null)
                {
                    _context.Vehicles.Remove(vehicle);
                }

                var userId = driver.UserId;
                _context.Drivers.Remove(driver);
                var user = _context.Users.Find(userId);
                _context.Users.Remove(user);

                _context.SaveChanges();
            }
        }
Esempio n. 2
0
        public ActionResult Create([Bind(Include = "TaxiID,TaxiModel,Color,RegisterNumber,TaxiType")] Taxi taxi)
        {
            if (ModelState.IsValid)
            {
                db.Taxis.Add(taxi);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(taxi));
        }
        /*public void UpdateOrder(Order order)
         * {
         *  throw new AppException("chua code");
         * }*/

        public void DeleteOrder(int id)
        {
            var order = _context.Orders.Find(id);

            if (order != null)
            {
                if (order.IsCancel == false || order.Status == false)
                {
                    order.Driver.Schedule.AvailablableSlot += order.Reservations;
                }
                _context.Orders.Remove(order);
                _context.SaveChanges();
            }
        }
Esempio n. 4
0
        public void MarkedRead(int notifyId)
        {
            var notify = _context.Notifies.Find(notifyId);

            notify.IsRead = true;
            _context.Notifies.Update(notify);
            _context.SaveChanges();
        }
Esempio n. 5
0
        public Review CreateReview(Review review)
        {
            review.Created = DateTime.Now;

            _context.Reviews.Add(review);
            _context.SaveChanges();

            return(review);
        }
Esempio n. 6
0
        //vehicle
        public Vehicle VCreate(Vehicle vehicle)
        {
            if (_context.Vehicles.Any(x => x.License == vehicle.License))
            {
                throw new AppException("Licence " + "'" + vehicle.License + "'" + "is already taken");
            }
            vehicle.Created = DateTime.Now;

            _context.Vehicles.Add(vehicle);
            _context.SaveChanges();

            return(vehicle);
        }
Esempio n. 7
0
        public static void Initialize(TaxiContext context)
        {
            var test = importTaxiTrips();

            //context.Database.EnsureDeleted();
            context.Database.EnsureCreated();

            if (context.TaxiTrips.Any())
            {
                return;
            }

            //add test data if the database is empty.

            var taxiTrips = importTaxiTrips();

            /* var taxiTrips = new TaxiTrip[]
             */
            foreach (TaxiTrip s in taxiTrips)
            {
                context.TaxiTrips.Add(s);
            }
            context.SaveChanges();
        }
Esempio n. 8
0
        public User Create(User user, string password, string origin)
        {
            //validation
            if (string.IsNullOrWhiteSpace(password))
            {
                throw new AppException("Password is required");
            }
            if (_context.Users.Any(x => x.UserName == user.UserName))
            {
                throw new AppException("Username \"" + user.UserName + "\" is already taken");
            }
            if (_context.Users.Any(x => x.Email == user.Email))
            {
                throw new AppException("Email \"" + user.Email + "\" is already taken");
            }

            byte[] passwordHash, passwordSalt;
            CreatePasswordHash(password, out passwordHash, out passwordSalt);

            user.PasswordHash = passwordHash;
            user.PasswordSalt = passwordSalt;

            if (string.IsNullOrWhiteSpace(user.Role))
            {
                user.Role = Role.Customer;
            }

            user.Created           = DateTime.Now;
            user.VerificationToken = randomTokenString();

            _context.Users.Add(user);
            _context.SaveChanges();

            sendVerificationEmail(user, origin);

            return(user);
        }
Esempio n. 9
0
 public void Save()
 {
     db.SaveChanges();
 }