Beispiel #1
0
        public ActionResult AddClient([Bind(Include = "Id_cli,Img,Name,Date_naiss,Dateè_Entre,Sport,Prix,Sexe")] Client client)
        {
            if (Request.Files.Count > 0)
            {
                HttpPostedFileBase files = Request.Files[0];

                string chemin = "";

                if (files.ContentLength > 0)
                {
                    chemin     = files.FileName;
                    client.Img = chemin;

                    var path = Path.Combine(Server.MapPath("~/Img"), chemin);
                    files.SaveAs(path);
                }
            }

            if (ModelState.IsValid)
            {
                db.Clients.Add(client);
                db.SaveChanges();
                return(RedirectToAction("Indexx"));
            }

            return(View("Indexx"));
        }
Beispiel #2
0
        public ActionResult Create([Bind(Include = "Vmatricule,Name,PrixKm,datePriseduKm,kilometrage,ImgUrl")] Voiture voiture)
        {
            if (Request.Files.Count > 0)
            {
                HttpPostedFileBase files = Request.Files[0];

                string chemin = "";

                if (files.ContentLength > 0)
                {
                    chemin         = files.FileName;
                    voiture.ImgUrl = chemin;

                    var path = Path.Combine(Server.MapPath("~/carsImg"), chemin);
                    files.SaveAs(path);
                }
            }
            if (ModelState.IsValid)
            {
                db.Voitures.Add(voiture);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(voiture));
        }
        public ActionResult Create([Bind(Include = "idlocation,dateReservation,datePaiment,Montant,idCli,idV")] LocationDeVoiture locationDeVoiture)
        {
            if (ModelState.IsValid)
            {
                db.LocationDeVoitures.Add(locationDeVoiture);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(locationDeVoiture));
        }
Beispiel #4
0
        public ActionResult Setdata(int km)
        {
            string  AE = Session["idV"].ToString();
            string  B  = Session["idc"].ToString();
            Voiture V  = db.Voitures.Find(int.Parse(AE));
            Client  c  = db.Clients.Find(int.Parse(B));
            Admin   A  = new Admin();
            int     H  = (int)V.PrixKm;

            LocationDeVoiture L = new LocationDeVoiture()
            {
                dateReservation = DateTime.Now,
                datePaiment     = DateTime.Now,
                Montant         = H * km,
                idCli           = c.Id_cli,
                idV             = V.Vmatricule,
                __  = null,
                _   = null,
                ___ = null
            };

            if (ModelState.IsValid)
            {
                try
                {
                    db.LocationDeVoitures.Add(L);
                    db.SaveChanges();
                    return(RedirectToAction("Index", "Home"));
                }
                catch (DbEntityValidationException e)
                {
                    foreach (var eve in e.EntityValidationErrors)
                    {
                        Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                          eve.Entry.Entity.GetType().Name, eve.Entry.State);
                        foreach (var ve in eve.ValidationErrors)
                        {
                            Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                              ve.PropertyName, ve.ErrorMessage);
                        }
                    }
                    throw;
                }
            }
            return(View());
        }
Beispiel #5
0
        public ActionResult Create([Bind(Include = "Id_cli,Nom,adresseClient,Tel,email,Password")] Client client)
        {
            if (ModelState.IsValid)
            {
                db.Clients.Add(client);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(client));
        }
        /// <summary>
        /// ایجاد کاربر بر اساس پارامتر ورودی
        /// </summary>
        /// <param name="name"></param>
        /// <param name="age"></param>
        /// <returns></returns>
        public IActionResult SetNewUser(string name, int age)
        {
            if (string.IsNullOrWhiteSpace(name) || age < 0)
            {
                return(new BadRequestResult());
            }

            var newuser = new UserModelDb {
                Age = age, Name = name
            };

            _dbCont.Users.Add(newuser);
            _dbCont.SaveChanges();
            return(new OkObjectResult(newuser));
        }