Exemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,StartTime,EndTime,EmployeeId,CarId")] RentedCars rentedCars)
        {
            if (id != rentedCars.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(rentedCars);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RentedCarsExists(rentedCars.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CarId"]      = new SelectList(_context.Cars, "carID", "Name", rentedCars.CarId);
            ViewData["EmployeeId"] = new SelectList(_context.Employees, "EmployeeID", "Name", rentedCars.EmployeeId);
            return(View(rentedCars));
        }
Exemplo n.º 2
0
        public IResult Add(RentedCars rentedCar)
        {
            var result = CheckReturnDate(rentedCar.CarId);

            if (!result.success)
            {
                return(new ErrorResult(""));
            }
            _rentedCar.Add(rentedCar);
            return(new SuccessResult("xx"));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("ID,StartTime,EndTime,EmployeeId,CarId")] RentedCars rentedCars)
        {
            if (ModelState.IsValid)
            {
                _context.Add(rentedCars);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CarId"]      = new SelectList(_context.Cars, "carID", "Name", rentedCars.CarId);
            ViewData["EmployeeId"] = new SelectList(_context.Employees, "EmployeeID", "Name", rentedCars.EmployeeId);
            return(View(rentedCars));
        }
        public async Task <JsonResult> RentCar(string ln, string id)
        {
            if (ModelState.IsValid)
            {
                HashSet <string>            hs1 = (HashSet <string>)Session["Veichles"];
                HashSet <string>            hs2 = (HashSet <string>)Session["Costumers"];
                Dictionary <string, string> d   = (Dictionary <string, string>)Session["RentedCars"];
                if (!hs1.Contains(ln) || !hs2.Contains(id) || (d.ContainsKey(id) && d[id].Equals(ln))) // checking if car and costumer are exist.
                {
                    return(await Task.Run(() => Json(1, JsonRequestBehavior.AllowGet)));
                }

                using (var db = new FleetMSEntities())
                {
                    try
                    {
                        var rc = new RentedCars();

                        //List<Costumer> costumerList = (List<Costumer>)Session["CostumersArray"];
                        //List<Veichle> veichleList = (List<Veichle>)Session["VeichlesArray"];
                        //rc.Costumer = Costumer.searchCostumer(costumers, id);
                        //rc.Veichle = Veichle.searchVeichles(veichles, ln);

                        Costumer[] costumers = await db.Costumer.ToArrayAsync();

                        Veichle[] veichles = await db.Veichle.ToArrayAsync();

                        rc.Costumer = Costumer.searchCostumer(costumers.ToList(), id); //find costumer
                        rc.Veichle  = Veichle.searchVeichles(veichles.ToList(), ln);   //find veichle
                        if (d.ContainsKey(rc.Costumer.Id))
                        {
                            return(await Task.Run(() => Json(2, JsonRequestBehavior.AllowGet)));
                        }

                        db.RentedCars.Add(rc);
                        await db.SaveChangesAsync();

                        //updating sessions
                        d.Add(rc.Costumer.Id, rc.Veichle.LicenseNumber);
                        Session["RentedCars"] = d;

                        return(await Task.Run(() => Json(0, JsonRequestBehavior.AllowGet)));
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Source);
                    }
                }
            }
            return(await Task.Run(() => Json(1, JsonRequestBehavior.AllowGet)));
        }
        public async Task <JsonResult> RemoveRentCar(string ln, string id)
        {
            if (ModelState.IsValid)
            {
                Dictionary <string, string> d = (Dictionary <string, string>)Session["RentedCars"];
                if (!(d.ContainsKey(id) && d[id].Equals(ln))) // checking if car or costumer are exist.
                {
                    return(await Task.Run(() => Json(1, JsonRequestBehavior.AllowGet)));
                }

                using (var db = new FleetMSEntities())
                {
                    try
                    {
                        RentedCars[] rentcar = await db.RentedCars.ToArrayAsync();

                        var rc = RentedCars.searchRentedCar(rentcar.ToList(), id, ln);

                        db.RentedCars.Attach(rc);
                        db.RentedCars.Remove(rc);
                        await db.SaveChangesAsync();

                        //updating sessions
                        d.Remove(id);
                        Session["RentedCars"] = d;

                        return(await Task.Run(() => Json(0, JsonRequestBehavior.AllowGet)));
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Source);
                    }
                }
            }
            return(await Task.Run(() => Json(1, JsonRequestBehavior.AllowGet)));
        }
Exemplo n.º 6
0
 public void Update(RentedCars rentedCar)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 7
0
 public IResult Delete(RentedCars rentedCar)
 {
     throw new NotImplementedException();
 }