Exemplo n.º 1
0
        public ActionResult Create([Bind(Include = "Id,Brand,Model,Year,Image,DailyPrice,VehicleTypeId")] VehicleDto input)
        {
            if (ModelState.IsValid)
            {
                string newfoto = null;
                if (input.Image != null && input.Image.ContentLength > 0)
                {
                    FileInfo fotoinfo = new FileInfo(input.Image.FileName);
                    newfoto = Guid.NewGuid().ToString() + fotoinfo.Extension;

                    string path = Path.Combine(Server.MapPath("~/Upload"),
                                               Path.GetFileName(newfoto));
                    input.Image.SaveAs(path);
                }
                var vehicle = new Vehicle()
                {
                    Brand         = input.Brand,
                    DailyPrice    = input.DailyPrice,
                    Image         = newfoto != null ? ("/Upload/" + newfoto) : null,
                    Model         = input.Model,
                    VehicleTypeId = input.VehicleTypeId,
                    Year          = input.Year
                };

                db.Vehicles.Add(vehicle);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.VehicleTypeId = new SelectList(db.VehicleTypes, "Id", "Type", input.VehicleTypeId);
            return(View(input));
        }
Exemplo n.º 2
0
        public ActionResult Create([Bind(Include = "Id,NazwaUrządzenia,MiesięcznyKosztWypożyczenia")] Urządzenie urządzenie)
        {
            if (ModelState.IsValid)
            {
                db.Urządzenia.Add(urządzenie);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(urządzenie));
        }
Exemplo n.º 3
0
        public ActionResult Create([Bind(Include = "Id,Name,Surname,Password,Email,RoleId")] User user)
        {
            if (ModelState.IsValid)
            {
                db.Users.Add(user);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.RoleId = new SelectList(db.Roles, "Id", "RoleName", user.RoleId);
            return(View(user));
        }
Exemplo n.º 4
0
        public static ResponseResult Create(List_User model)
        {
            ResponseResult result = new ResponseResult();

            try
            {
                using (var db = new RentalContext())
                {
                    data_user User = new data_user();

                    User.Id = Guid.NewGuid().ToString();
                    //User.Id = "123abv";
                    User.Email    = model.Email;
                    User.Nama     = model.Nama;
                    User.Alamat   = model.Alamat;
                    User.nomor_id = model.nomor_id;

                    db.data_users.Add(User);
                    db.SaveChanges();

                    result.list    = model;
                    result.success = true;
                }
            }
            catch (Exception ex)
            {
                result.success = false;
                result.message = ex.Message;
                throw;
            }



            return(result);
        }
Exemplo n.º 5
0
        public static ResponseResult Create(Rent_lists model)
        {
            ResponseResult result = new ResponseResult();

            try
            {
                using (var db = new RentalContext())
                {
                    DataRent User = new DataRent();

                    User.Id = Guid.NewGuid().ToString();
                    //User.Id = "123abv";
                    User.id_Kendaraan  = model.id_Kendaraan;
                    User.Start_Date    = model.Start_Date;
                    User.End_Date      = model.End_Date;
                    User.Nomor_Pesanan = DateTime.Now.ToString("ddmmyyyy") + "001";

                    db.DataRents.Add(User);
                    db.SaveChanges();

                    result.list    = model;
                    result.success = true;
                }
            }
            catch (Exception ex)
            {
                result.success = false;
                result.message = ex.Message;
                throw;
            }



            return(result);
        }
Exemplo n.º 6
0
        public ActionResult CreateRetail(int vehicleId, DateTime startDate, DateTime endDate)
        {
            var user = HttpContext.Session["UserInfo"] as UserInfo;

            var checkRentals = _context.Rentals
                               .Where(x => x.VehicleId == vehicleId &&
                                      (((x.StartDate >= startDate && x.EndDate >= endDate)) || ((x.EndDate >= startDate))))
                               .FirstOrDefault();

            if (checkRentals != null)
            {
                TempData["RentalError"] = "Arac bu " + checkRentals.StartDate.ToString("dd-MM-yyyy") + "-" + checkRentals.EndDate.ToString("dd-MM-yyyy") + " tarihler arasında dolu";
                return(RedirectToAction("Index", "Vehicle", new { id = vehicleId, startDate = startDate, endDate = endDate }));
            }
            var arac = _context.Vehicles.Find(vehicleId);

            _context.Rentals.Add(new Rental()
            {
                UserId     = user.Id,
                VehicleId  = vehicleId,
                StartDate  = startDate,
                EndDate    = endDate,
                TotalPrice = ((endDate - startDate).TotalDays + 1) * arac.DailyPrice
            });
            _context.SaveChanges();
            TempData["RentalSuccess"] = "Arac bu " + startDate.ToString("dd-MM-yyyy") + "-" + endDate.ToString("dd-MM-yyyy") + " tarihler arasında başarıyla kiralandı";
            return(RedirectToAction("Index", "Home"));
        }
Exemplo n.º 7
0
        public ActionResult Create([Bind(Include = "ZamówienieId,Imie,Nazwisko,Ulica,NumerDomu,NumerMieszkania,KosztZamówienia,IlośćMiesięcyWypożyczenia,DataZłożenia,DataZwrotu,UrządzenieId,MiesięcznyKosztWypożyczenia")] Zamówienie zamówienie, Urządzenie urządzenie)
        {
            if (ModelState.IsValid)
            {
                zamówienie.całkowityKoszt(urządzenie);

                zamówienie.dataZwrotu(zamówienie.IlośćMiesięcyWypożyczenia);

                zamówienie.sprawdźDate();
                db.Zamówienia.Add(zamówienie);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.UrządzenieId = new SelectList(db.Urządzenia, "Id", "NazwaUrządzenia", zamówienie.UrządzenieId);
            return(View(zamówienie));
        }
        public ActionResult Delete(int Id)
        {
            using (var db = new RentalContext())
            {
                var rental = db.Rentals.Find(Id);
                db.Rentals.Remove(rental);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }
        }
Exemplo n.º 9
0
        public ActionResult Register(User input)
        {
            input.Password = Code.Helper.CreateMD5(input.Password);

            var user = _context.Users.AsQueryable().Include(y => y.Role).FirstOrDefault(r => r.Email == input.Email && r.Password == input.Password);

            if (user == null)
            {
                user = input;
                var userRole = _context.Roles.FirstOrDefault(x => x.RoleName == "User");
                if (userRole == null)
                {
                    userRole = _context.Roles.Add(new Role()
                    {
                        RoleName = "User"
                    });
                    _context.SaveChanges();
                    userRole = _context.Roles.FirstOrDefault(x => x.RoleName == "User");
                }
                user.RoleId = userRole.Id;

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

                FormsAuthentication.SetAuthCookie(user.Id.ToString(), false);
                HttpContext.Session["UserInfo"] = new UserInfo()
                {
                    Id       = user.Id,
                    FullName = user.Name + " " + user.Surname,
                    RoleName = user.Role.RoleName
                };

                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                ViewBag.ErrorMsg = "E-posta veya şifrenizi doğru giriniz.";
                return(View());
            }
        }
        public ActionResult Edit(int Id, string firstName, string lastName, string movieTitle,
                                 string emailAddress, DateTime checkOutDate)
        {
            using (var db = new RentalContext())
            {
                var rental = db.Rentals.Find(Id);
                rental.FirstName    = firstName;
                rental.LastName     = lastName;
                rental.MovieTitle   = movieTitle;
                rental.Email        = emailAddress;
                rental.CheckOutDate = checkOutDate;
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }
        }
Exemplo n.º 11
0
 public void Add(Guitar newGuitar)
 {
     _context.Add(newGuitar);
     _context.SaveChanges();
 }
 public void Add(DistributionCenter newCenter)
 {
     _context.Add(newCenter);
     _context.SaveChanges();
 }
Exemplo n.º 13
0
 public void Add(RentalAsset newAsset)
 {
     _context.Add(newAsset);
     _context.SaveChanges();
 }
Exemplo n.º 14
0
 /// <summary>
 /// taking out of availability cars that are renting today
 /// </summary>
 private void UpdateCars()
 {
     foreach (var item in db.Rentals.ToList())
     {
         if (item.StartDate == DateTime.Today)
         {
             Car car = db.Cars.Find(item.Car.ID);
             car.IsAvailable = false;
             db.SaveChanges();
         }
     }
 }
 public void Add(Inventory newInventory)
 {
     _context.Add(newInventory);
     _context.SaveChanges();
 }
 public void Add(Rental newRental)
 {
     _context.Add(newRental);
     _context.SaveChanges();
 }
 public void Add(Subscriber newSubscriber)
 {
     _context.Add(newSubscriber);
     _context.SaveChanges();
 }