示例#1
0
        public ActionResult Create([Bind(Include = "id,custname,address,mobile")] customer customer)
        {
            if (ModelState.IsValid)
            {
                db.customers.Add(customer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(customer));
        }
        public ActionResult Create(PickLocation picklocation)
        {
            if (ModelState.IsValid)
            {
                db.PickLocations.Add(picklocation);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(picklocation));
        }
示例#3
0
 public ActionResult Create([Bind(Exclude = "Id")] Car carDetails)
 {
     if (!ModelState.IsValid)
     {
         return(View());
     }
     obj.Cars.Add(carDetails);
     obj.SaveChanges();
     //Response.Redirect("StudentAdmission",true);
     return(RedirectToAction("CarDetails"));
 }
示例#4
0
        public ActionResult Create(CarMake carmake)
        {
            if (ModelState.IsValid)
            {
                db.CarMakes.Add(carmake);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(carmake));
        }
示例#5
0
 public ActionResult Create([Bind(Exclude = "Id")] Booking data)
 {
     if (!ModelState.IsValid)
     {
         return(View());
     }
     obj.Bookings.Add(data);
     obj.SaveChanges();
     //Response.Redirect("StudentAdmission",true);
     return(RedirectToAction("BookingList"));
 }
示例#6
0
        public ActionResult Create(Rental rental)
        {
            if (ModelState.IsValid)
            {
                db.Rentals.Add(rental);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CarId      = new SelectList(db.CarInfoes, "CarId", "CarModel", rental.CarId);
            ViewBag.CustomerId = new SelectList(db.CustomerInfoes, "CustomerId", "CustomerName", rental.CustomerId);
            ViewBag.DriverId   = new SelectList(db.DriverInfoes, "DriverId", "DriverName", rental.DriverId);
            ViewBag.LocationId = new SelectList(db.PickLocations, "LocationId", "Country", rental.LocationId);
            return(View(rental));
        }
        public bool EditUserRgistrationForm([FromBody] UserModel usermastertb)
        {
            try
            {
                var output = (from usermaster in db.Users
                              where usermastertb.UserID == usermaster.UserID
                              select usermaster.UserName).Count();

                if (output > 0)
                {
                    return(false);
                }
                else
                {
                    var userTypeID = (from user in db.UserTypes
                                      where user.TypeOfUser == "Admin"
                                      select user.UserTypeID).SingleOrDefault();

                    //  usermastertb.UserTypeID = User.GetType;

                    db.SaveChanges();

                    return(true);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
示例#8
0
 public ActionResult Booking(BookingViewModel car)
 {
     using (CarRentalEntities db = new CarRentalEntities())
     {
         if (ModelState.IsValid)
         {
             var bookingCar = new Booking()
             {
                 StartDate = car.StartDate,
                 EndDate   = car.EndDate,
                 CarName   = car.CarName,
                 Email     = HttpContext.User.Identity.Name
             };
             db.Booking.Add(bookingCar);
             db.SaveChanges();
             message = "Rezerwacja zakończona pomyślnie. Dziękujemy za skorzystanie z naszej oferty. Historię rezerwacji możesz sprawdzić w panelu swojego konta użytkownika.";
             Status  = true;
         }
         else
         {
             message = "Nieprawidłowe żądanie";
             Status  = false;
         }
     }
     ViewBag.Message = message;
     ViewBag.Status  = Status;
     return(View(car));
 }
 public bool UpdateBranch(BranchModel updatedBranch)
 {
     try
     {
         using (CarRentalEntities carEntities = new CarRentalEntities())
         {
             Branch branch = carEntities.Branches.Where(b => b.BranchId == updatedBranch.BranchId).FirstOrDefault();
             if (branch == null)
             {
                 throw new ArgumentException($"Branch not found");
             }
             branch.Address          = updatedBranch.Address;
             branch.BranchName       = updatedBranch.BranchName;
             branch.Latitude         = updatedBranch.Coordinates.Latitude;
             branch.LatitudeMinutes  = updatedBranch.Coordinates.LatitudeMinutes;
             branch.IsNorth          = updatedBranch.Coordinates.IsNorth;
             branch.Longitude        = updatedBranch.Coordinates.Longitude;
             branch.LongitudeMinutes = updatedBranch.Coordinates.LongitudeMinutes;
             branch.IsEast           = updatedBranch.Coordinates.IsEast;
             carEntities.SaveChanges();
         }
         return(true);
     }
     catch
     {
         return(false);
     }
 }
示例#10
0
 public BranchModel AddBranch(BranchModel addBranch)
 {
     try
     {
         using (CarRentalEntities carEntities = new CarRentalEntities())
         {
             Branch branch = new Branch();
             branch.Address          = addBranch.Address;
             branch.BranchName       = addBranch.BranchName;
             branch.Latitude         = addBranch.Coordinates.Latitude;
             branch.LatitudeMinutes  = addBranch.Coordinates.LatitudeMinutes;
             branch.IsNorth          = addBranch.Coordinates.IsNorth;
             branch.Longitude        = addBranch.Coordinates.Longitude;
             branch.LongitudeMinutes = addBranch.Coordinates.LongitudeMinutes;
             branch.IsEast           = addBranch.Coordinates.IsEast;
             carEntities.Branches.Add(branch);
             carEntities.SaveChanges();
             addBranch.BranchId = branch.BranchId;
         }
         return(addBranch);
     }
     catch
     {
         return(null);
     }
 }
示例#11
0
        public IHttpActionResult PutOrder([FromUri] int id, [FromBody] Order order)
        {
            if (id != order.OrderID)
            {
                return(BadRequest());
            }

            db.Entry(order).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!IsAvail(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
示例#12
0
 public bool UpdateCar(CarModel updatedCar)
 {
     try
     {
         using (CarRentalEntities carEntities = new CarRentalEntities())
         {
             Car car = carEntities.Cars.Where(c => c.LicensePlate == updatedCar.LicensePlate).FirstOrDefault();
             if (car == null)
             {
                 throw new ArgumentException($"Car with license plate {updatedCar.LicensePlate} was not found");
             }
             car.CarTypeId     = CarTypesManager.getCarTypeId(updatedCar.CarType.Producer, updatedCar.CarType.Model, updatedCar.CarType.ManufacturingYear, updatedCar.CarType.Gear);
             car.Kilometers    = updatedCar.CurrentKM;
             car.Photo         = updatedCar.CarPhoto;
             car.IsConditionOK = updatedCar.IsFunctional;
             car.BranchId      = updatedCar.Branch.BranchId;
             carEntities.SaveChanges();
         }
         return(true);
     }
     catch
     {
         return(false);
     }
 }
示例#13
0
 public bool deleteCarType(CarTypeModel carTypeToDelete)//todo: add field isactive and instead of delete, set to inactive. change the select all to ignore inactive
 {
     try
     {
         using (CarRentalEntities carEntities = new CarRentalEntities())
         {
             CarType carTypeToDel = null;
             foreach (var singleCarType in carEntities.CarTypes)
             {
                 if (singleCarType.Manufacturer == carTypeToDelete.Producer &&
                     singleCarType.Model == carTypeToDelete.Model && singleCarType.ProductionYear == carTypeToDelete.ManufacturingYear && (singleCarType.AutomaticGear && carTypeToDelete.Gear == CarTypeModel.AUTOMATIC || !singleCarType.AutomaticGear && carTypeToDelete.Gear == CarTypeModel.MANUAL))
                 {
                     //found!!
                     carTypeToDel = singleCarType;
                     break;
                 }
             }
             if (carTypeToDel != null)
             {
                 carEntities.CarTypes.Remove(carTypeToDel);
                 carEntities.SaveChanges();
                 return(true);
             }
         }
         return(false);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
        public bool EditCar(CarModel b)
        {
            using (CarRentalEntities db = new CarRentalEntities())
            {
                try
                {
                    Car bk = db.Cars.FirstOrDefault(Car => Car.CarNum == b.CarNum);
                    if (bk != null)
                    {
                        bk.IsAvailable = b.IsAvailable;
                        bk.CarID       = b.CarID;
                        bk.KM          = b.KM;
                        bk.IsFix       = b.IsFix;


                        db.SaveChanges();
                        return(true);
                    }
                    return(false);
                }
                catch (Exception)
                {
                    return(false);
                }
            }
        }
示例#15
0
 public bool deleteUser(UserModel userToDelete)
 {
     try
     {
         using (CarRentalEntities carEntities = new CarRentalEntities())
         {
             User userToDel = null;
             foreach (var singleUser in carEntities.Users)
             {
                 if (singleUser.UserName == userToDelete.UserName)
                 {
                     //found!!
                     userToDel = singleUser;
                     break;
                 }
             }
             if (userToDel != null)
             {
                 carEntities.Users.Remove(userToDel);
                 carEntities.SaveChanges();
                 return(true);
             }
         }
         return(false);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
示例#16
0
        public int AddNewOrder(string userName, RentalOrderModel order, out string errorMessage)
        {
            errorMessage = "";
            try
            {
                if (order.StartRent.Date < DateTime.Now.Date)
                {
                    errorMessage = $"The order start date {order.StartRent.Date} should be today {DateTime.Now.Date} or later";
                    return(-3);
                }
                if (order.EndRent.Date <= order.StartRent.Date)
                {
                    errorMessage = "The order end date should be greater than the start date";
                    return(-3);
                }
                using (CarRentalEntities carEntities = new CarRentalEntities())
                {
                    Car car = carEntities.Cars.Where(c => c.LicensePlate == order.CarToRent.LicensePlate).FirstOrDefault();
                    if (car == null)
                    {
                        errorMessage = "Car not found";
                        return(-1);
                    }
                    User user = carEntities.Users.Where(u => u.UserName == order.RentingUser.UserName).FirstOrDefault();
                    if (user == null)
                    {
                        errorMessage = "User not found";
                        return(-1);
                    }
                    RentalOrder newOrder = new RentalOrder()
                    {
                        CarId             = car.CarId,
                        UserId            = user.UserId,
                        RentStartDate     = order.StartRent,
                        RentEndDate       = order.EndRent,
                        ActualRentEndDate = order.ActualEndRent
                    };

                    //In a real-life application, the following should be done using a transaction, or with some locking mechanism!
                    foreach (var o in carEntities.RentalOrders)
                    {
                        if (clash(o, newOrder))
                        {
                            errorMessage = "Sorry, the car you selected is not available on these dates. Please change the dates or select another car";
                            return(-2);
                        }
                    }

                    carEntities.RentalOrders.Add(newOrder);
                    carEntities.SaveChanges();
                    return(newOrder.RentalOrderId);
                }
            }
            catch (Exception e)
            {
                return(-1);
            }
        }
示例#17
0
        private void btn_Reset_Click(object sender, EventArgs e)
        {
            try
            {
                //get the record object from selection
                var id   = (int)dgv_UserList.SelectedRows[0].Cells["Id"].Value;
                var user = _db.Users.FirstOrDefault(a => a.Id == id);

                ResetPasswordForm rpf = new ResetPasswordForm(user);

                var result = rpf.ShowDialog();
                _db.SaveChanges();
            }
            catch (Exception)
            {
                MessageBox.Show("Select at least one row.");
            }
        }
示例#18
0
        public bool UpdateOrder(RentalOrderModel updatedOrder, out string errorMessage)
        {
            try
            {
                errorMessage = "";

                if (updatedOrder.EndRent.Date <= updatedOrder.StartRent.Date)
                {
                    errorMessage = $"The order end date {updatedOrder.EndRent.Date} should be greater than the start date {updatedOrder.StartRent.Date}";
                    return(false);
                }
                using (CarRentalEntities carEntities = new CarRentalEntities())
                {
                    Car car = carEntities.Cars.Where(c => c.LicensePlate == updatedOrder.CarToRent.LicensePlate).FirstOrDefault();
                    if (car == null)
                    {
                        errorMessage = $"Car {updatedOrder.CarToRent.LicensePlate} was not found";
                        return(false);
                    }
                    User user = carEntities.Users.Where(u => u.UserName == updatedOrder.RentingUser.UserName).FirstOrDefault();
                    if (user == null)
                    {
                        errorMessage = $"Renting user {updatedOrder.RentingUser.UserName} ({updatedOrder.RentingUser.FullName}) was not found";
                        return(false);
                    }

                    RentalOrder order = carEntities.RentalOrders.Where(o => o.RentalOrderId == updatedOrder.OrderId).FirstOrDefault();
                    if (order == null)
                    {
                        errorMessage = $"Order number {updatedOrder.OrderId} was not found";
                        return(false);
                    }
                    order.RentStartDate     = updatedOrder.StartRent;
                    order.RentEndDate       = updatedOrder.EndRent;
                    order.ActualRentEndDate = updatedOrder.ActualEndRent;
                    order.UserId            = user.UserId;
                    order.CarId             = car.CarId;
                    //In a real-life application, the following should be done using a transaction, or with some locking mechanism!
                    foreach (var o in carEntities.RentalOrders)
                    {
                        if (clash(o, order))
                        {
                            errorMessage = "Sorry, the car you selected is not available on these dates. Please change the dates or select another car";
                            return(false);
                        }
                    }

                    carEntities.SaveChanges();
                }
                return(true);
            }
            catch (Exception e)
            {
                errorMessage = e.Message;
                return(false);
            }
        }
        private void btn_Delete_Click(object sender, EventArgs e)
        {
            var id  = (int)dgv_VehicleList.SelectedRows[0].Cells["Id"].Value;
            var car = _db.Cars.FirstOrDefault(x => x.Id == id);

            _db.Cars.Remove(car);
            _db.SaveChanges();

            dgv_VehicleList.Refresh();
        }
        public ActionResult Create(Cars cars)
        {
            if (ModelState.IsValid)
            {
                var file = Request.Files[0];
                if (file != null && file.ContentLength > 0)
                {
                    var fileName = Path.GetFileName(file.FileName);
                    var path     = Path.Combine(Server.MapPath("~/App_Data/Images/"), fileName);
                    file.SaveAs(path);
                    cars.Photo = path;
                }
                db.Cars.Add(cars);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            ViewBag.CarTypeId = new SelectList(db.CarType, "Id", "Type", cars.CarTypeId);
            return(View(cars));
        }
示例#21
0
 public ActionResult Register(RegisterViewModels user)
 {
     if (ModelState.IsValid)
     {
         if (securityService.EmailExist(user.Email))
         {
             message = "Podany email został już zarejestrowany";
         }
         else
         {
             var newuser = new Users()
             {
                 email       = user.Email,
                 password    = user.Password,
                 firstname   = user.FirstName,
                 lastname    = user.LastName,
                 city        = user.City,
                 address     = user.Address,
                 number      = user.Number,
                 zipcode     = user.ZipCode,
                 phonenumber = user.PhoneNumber
             };
             db.Users.Add(newuser);
             db.SaveChanges();
             message = "Rejestracja zakończona pomyślnie. Możesz zalogować sie na swoje konto.";
             Status  = true;
         }
     }
     else
     {
         message = "Nieprawidłowe żądanie";
         Status  = false;
     }
     ViewBag.Message = message;
     ViewBag.Status  = Status;
     return(View(user));
 }
示例#22
0
        private void btn_Save_Click(object sender, EventArgs e)
        {
            if (isEditMode)
            {
                //Edit code here
                var id        = int.Parse(lbl_Id.Text);
                var carToEdit = _db.Cars.FirstOrDefault(x => x.Id == id);

                carToEdit.Make  = txt_Make.Text;
                carToEdit.Model = txt_Model.Text;
                carToEdit.LicensePlateNumber = txt_LicensePlate.Text;
                carToEdit.VIN  = txt_Vin.Text;
                carToEdit.Year = int.Parse(txt_Year.Text);

                _db.SaveChanges();
                MessageBox.Show("Data saved successfully");
                this.Close();
            }
            else
            {
                //Add code here
                Car carToEdit = new Car()
                {
                    Make  = txt_Make.Text,
                    Model = txt_Model.Text,
                    LicensePlateNumber = txt_LicensePlate.Text,
                    VIN  = txt_Vin.Text,
                    Year = int.Parse(txt_Year.Text)
                };

                _db.Cars.Add(carToEdit);
                _db.SaveChanges();
                MessageBox.Show("Data edited successfully");
                this.Close();
            }
        }
示例#23
0
        public bool EditUsersPassword(UserModel user, LoginModel password)
        {
            using (CarRentalEntities db = new CarRentalEntities())
            {
                User u = db.Users.FirstOrDefault(a => a.UserName == user.UserName && a.Password == password.Password);

                if (u != null)
                {
                    u.Password = password.Password;
                    db.SaveChanges();
                    return(true);
                }
                return(false);
            }
        }
示例#24
0
 private void btn_Delete_Click(object sender, EventArgs e)
 {
     try
     {
         var id     = (int)dgv_RecordList.SelectedRows[0].Cells["idDataGridViewTextBoxColumn"].Value;
         var record = _db.CarRentalRecords.FirstOrDefault(a => a.Id == id);
         _db.CarRentalRecords.Remove(record);
         _db.SaveChanges();
         ManageRentalRecodrs_Load(sender, e);
     }
     catch (Exception)
     {
         MessageBox.Show("Select at least one row");
     }
 }
示例#25
0
 public ActionResult Save(rentail rent)
 {
     if (ModelState.IsValid)
     {
         db.rentails.Add(rent);
         var car = db.carregs.SingleOrDefault(e => e.carno == rent.carid);
         if (car == null)
         {
             return(HttpNotFound("CarNo is not valid"));
         }
         car.available       = "no";
         db.Entry(car).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(rent));
 }
        public bool AddCar(CarModel car)
        {
            try {
                using (CarRentalEntities db = new CarRentalEntities())
                {
                    Car c = db.Cars.Where(a => car.CarID == a.CarID).FirstOrDefault();
                    if (c != null)
                    {
                        return(false);
                    }
                };

                db.Cars.Add(new Car
                {
                    CarNum      = car.CarNum,
                    CarPic      = car.CarPic,
                    KM          = car.KM,
                    IsAvailable = car.IsAvailable,
                    IsFix       = car.IsFix,
                    CarType     = new CarType
                    {
                        Brand            = car.CarType.Brand,
                        Model            = car.CarType.Model,
                        IsManual         = car.CarType.IsManual,
                        PriceExtraPerDay = car.CarType.PriceExtraPerDay,
                        PricePerDay      = car.CarType.PricePerDay,
                        Year             = car.CarType.Year
                    },
                    Branch = new Branch
                    {
                        Name       = car.Branch.Name,
                        Address    = car.Branch.Address,
                        Latitude   = car.Branch.Latitude,
                        Longtitude = car.Branch.Longtitude
                    }
                });

                db.SaveChanges();
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
示例#27
0
        public JwtPacket Register([FromBody] User user)
        {
            User newuser = db.Users.Where(a => a.UserName == user.UserName).FirstOrDefault();

            if (newuser != null)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound));
            }
            var jwt        = new JwtSecurityToken();
            var encodedJwt = new JwtSecurityTokenHandler().WriteToken(jwt);

            //var x = um.AddUser(user);
            db.Users.Add(user);
            db.SaveChanges();

            return(CreateJwtPacket(user));
            //return new JwtPacket() { Token = encodedJwt, UserName=user.UserName};
        }
示例#28
0
 public bool deleteCar(string carLicensePlateToDelete)//todo: add field isactive and instead of delete, set to inactive. change the select all to ignore inactive
 {
     try
     {
         using (CarRentalEntities carEntities = new CarRentalEntities())
         {
             Car car = carEntities.Cars.Where(c => c.LicensePlate == carLicensePlateToDelete).FirstOrDefault();
             if (car != null)
             {
                 carEntities.Cars.Remove(car);
                 carEntities.SaveChanges();
             }
         }
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
示例#29
0
 public bool deleteBranch(string branchToDelete)
 {
     try
     {
         using (CarRentalEntities carEntities = new CarRentalEntities())
         {
             Branch branch = carEntities.Branches.Where(b => b.BranchName == branchToDelete).FirstOrDefault();
             if (branch != null)
             {
                 carEntities.Branches.Remove(branch);
                 carEntities.SaveChanges();
             }
         }
         return(true);
     }
     catch
     {
         return(false);
     }
 }
示例#30
0
 public bool DeleteOrder(RentalOrderModel updatedOrder)
 {
     try
     {
         using (CarRentalEntities carEntities = new CarRentalEntities())
         {
             RentalOrder order = carEntities.RentalOrders.Where(o => o.RentalOrderId == updatedOrder.OrderId).FirstOrDefault();
             if (order == null)
             {
                 throw new ArgumentException($"Order number {updatedOrder.OrderId} was not found");
             }
             carEntities.RentalOrders.Remove(order);
             carEntities.SaveChanges();
         }
         return(true);
     }
     catch
     {
         return(false);
     }
 }