예제 #1
0
        public ActionResult Edit(String id, Agince agince)
        {
            try
            {
                var newAgince = db.Agince.FirstOrDefault(agince_ => agince_.Agince_ID == id);

                if (agince.photo_path != null)
                {
                    newAgince.name         = agince.name;
                    newAgince.phone_number = agince.phone_number;
                    /*Add photo to Data Base*/
                    string filename  = Path.GetFileNameWithoutExtension(agince.photo_path.FileName);
                    string Extintion = Path.GetExtension(agince.photo_path.FileName);
                    filename = filename + DateTime.Now.ToString("yymmssfff") + Extintion;
                    newAgince.photo_Agince = filename;
                    filename = Path.Combine(Server.MapPath("~/images/"), filename);
                    agince.photo_path.SaveAs(filename);
                    //----------------------------/
                }
                db.SaveChanges();
                return(RedirectToAction("List_Of_All"));
            }
            catch
            {
                return(View("Edit"));
            }
        }
예제 #2
0
        public ActionResult Create(Car car)
        {
            try
            {
                string Agince_ID = User.Identity.GetUserId();
                Agince agince    = db.Agince.FirstOrDefault(agince_ => agince_.Agince_ID == Agince_ID);
                if (car.photo_path != null)
                {
                    string filename  = Path.GetFileNameWithoutExtension(car.photo_path.FileName);
                    string Extintion = Path.GetExtension(car.photo_path.FileName);
                    filename      = filename + DateTime.Now.ToString("yymmssfff") + Extintion;
                    car.photo_Car = filename;
                    filename      = Path.Combine(Server.MapPath("~/images/"), filename);
                    car.photo_path.SaveAs(filename);
                }
                car.Agince_Of_Car = agince;
                agince.Collection_Of_Car.Add(car);
                db.Cars.Add(car);
                if (agince.Agince_ID != null)
                {
                    car.Agince_Of_Car = agince;
                }

                db.SaveChanges();
                return(RedirectToAction("List_Of_All", "Car_properties", car));
            }
            catch
            {
                return(View(car));
            }
        }
        public ActionResult Edit(int id, Agince agince, string password)
        {
            try
            {
                var newAgince = context.Agince.FirstOrDefault(agince_ => agince_.ID == id);

                if (newAgince.password == password)
                {
                    newAgince.password         = password;
                    newAgince.confirm_Password = password;
                    newAgince.name             = agince.name;
                    newAgince.phone_number     = agince.phone_number;
                    /*Add photo to Data Base*/
                    string filename  = Path.GetFileNameWithoutExtension(agince.photo_path.FileName);
                    string Extintion = Path.GetExtension(agince.photo_path.FileName);
                    filename = filename + DateTime.Now.ToString("yymmssfff") + Extintion;
                    newAgince.photo_Agince = filename;
                    filename = Path.Combine(Server.MapPath("~/images/"), filename);
                    agince.photo_path.SaveAs(filename);
                    //----------------------------//
                }
                else
                {
                    return(View("Edit"));
                }


                context.SaveChanges();
                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View("Edit"));
            }
        }
예제 #4
0
        public ActionResult DeleteConfirmed(string id)
        {
            Agince agince = db.Agince.Find(id);

            db.Agince.Remove(agince);
            db.SaveChanges();
            return(RedirectToAction("List_Of_All"));
        }
예제 #5
0
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Car car = db.Cars.FirstOrDefault(Car_ => Car_.Car_Id == id);
            cars_and_properties cars_And_Properties = new cars_and_properties();

            cars_And_Properties.Property_Name =
                (from car_ in db.Car_And_Properites
                 where (car_.Cars.Car_Id == car.Car_Id)
                 select(
                     car_.properties.proprity_Name
                     )).ToList();

            Dates_For_Car Date = new Dates_For_Car();

            Date.Start_Recive = (from Dates in db.ReciveDates
                                 where (Dates.cars.Car_Id == car.Car_Id)
                                 select
                                 (
                                     Dates.Start_Recive_Date
                                 )).ToList();
            Date.End_Recive = (from Dates in db.ReciveDates
                               where (Dates.cars.Car_Id == car.Car_Id)
                               select
                               (
                                   Dates.End_Recive_Date
                               )).ToList();
            Date.Clients = (from Dates in db.ReciveDates
                            where (Dates.cars.Car_Id == car.Car_Id)
                            select
                            (
                                Dates.client
                            )).ToList();
            Agince agince = (from ca in db.Cars
                             from ag in db.Agince
                             where (ag.Agince_ID == ca.Agince_Of_Car.Agince_ID)
                             select(ag)).FirstOrDefault();

            ViewBag.Agince = agince;
            ViewBag.list_of_Recived_Date = Date;
            ViewBag.list_of_properties   = cars_And_Properties;

            if (car == null)
            {
                return(HttpNotFound());
            }
            return(View(car));
        }
예제 #6
0
        // GET: Aginces/Edit/5
        public ActionResult Edit(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Agince agince = db.Agince.Find(id);

            if (agince == null)
            {
                return(HttpNotFound());
            }
            return(View(agince));
        }
        // GET: Agince/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Agince aganis_Car = context.Agince.Find(id);

            if (aganis_Car == null)
            {
                return(HttpNotFound());
            }
            return(View(aganis_Car));
        }
예제 #8
0
        public ActionResult Edit(Agince agince)
        {
            if (ModelState.IsValid)
            {
                string filename  = Path.GetFileNameWithoutExtension(agince.photo_path.FileName);
                string Extintion = Path.GetExtension(agince.photo_path.FileName);
                filename            = filename + DateTime.Now.ToString("yymmssfff") + Extintion;
                agince.photo_Agince = filename;
                filename            = Path.Combine(Server.MapPath("~/images/"), filename);
                agince.photo_path.SaveAs(filename);


                db.Entry(agince).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("List_Of_All"));
            }
            return(View(agince));
        }
예제 #9
0
        public ActionResult Create(Agince agince)
        {
            if (ModelState.IsValid)
            {
                //string filename = Path.GetFileNameWithoutExtension(agince.photo_path.FileName);
                //string Extintion = Path.GetExtension(agince.photo_path.FileName);
                //filename = filename + DateTime.Now.ToString("yymmssfff") + Extintion;
                //agince.photo_Agince = filename;
                //filename = Path.Combine(Server.MapPath("~/images/"), filename);
                //agince.photo_path.SaveAs(filename);

                db.Agince.Add(agince);
                db.SaveChanges();
                return(RedirectToAction("List_Of_All"));
            }

            return(View(agince));
        }
예제 #10
0
        public ActionResult Create(string password, Agince agince)
        {
            #region Old_Creat
            //try
            //{
            //    agince.password = password;
            //    /*Add photo to Data Base*/
            //    string filename = Path.GetFileNameWithoutExtension(agince.photo_path.FileName);
            //    string Extintion = Path.GetExtension(agince.photo_path.FileName);
            //    filename = filename + DateTime.Now.ToString("yymmssfff") + Extintion;
            //    agince.photo_Agince =filename;
            //    filename = Path.Combine(Server.MapPath("~/images/"), filename);
            //    agince.photo_path.SaveAs(filename);
            //    //----------------------------//
            //    context.Agince.Add(agince);
            //    context.SaveChanges();
            //    return RedirectToAction("Index","Home");
            //}
            //catch
            //{
            //    return View("Create");
            //}
            #endregion
            if (ModelState.IsValid)
            {
                /*Add photo to Data Base*/
                string filename  = Path.GetFileNameWithoutExtension(agince.photo_path.FileName);
                string Extintion = Path.GetExtension(agince.photo_path.FileName);
                filename            = filename + DateTime.Now.ToString("yymmssfff") + Extintion;
                agince.photo_Agince = filename;
                filename            = Path.Combine(Server.MapPath("~/images/"), filename);
                agince.photo_path.SaveAs(filename);
                //----------------------------//
                context.Agince.Add(agince);
                context.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(agince));
        }
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (model.Roles == "Client" && ModelState.IsValid)
                {
                    Client clinet = new Client();

                    if (db.Client.FirstOrDefault(w => w.Client_ID == model.Id) != null)
                    {
                        db.Client.Remove(db.Client.FirstOrDefault(w => w.Client_ID == model.Id));
                        db.SaveChanges();
                        clinet.Client_ID = (model.Id); //  اقصد به رقم البطاقه
                        clinet.Name      = model.UserName;
                        //clinet.password = model.Password;
                        clinet.phone_Number = model.PhoneNumber;
                        clinet.city         = model.city;
                        clinet.street       = model.Street;
                        context.Client.Add(clinet);
                        context.SaveChanges();
                    }
                    else
                    {
                        clinet.Client_ID = (model.Id); //  اقصد به رقم البطاقه
                        clinet.Name      = model.UserName;
                        // clinet.password = model.Password;
                        clinet.phone_Number = model.PhoneNumber;
                        clinet.city         = model.city;
                        clinet.street       = model.Street;
                        context.Client.Add(clinet);
                        context.SaveChanges();
                    }
                }


                else if (model.Roles == "Agince" && ModelState.IsValid)
                {
                    Agince aganis_Car = new Agince();
                    if (db.Agince.FirstOrDefault(w => w.Agince_ID == model.Id) != null)
                    {
                        db.Agince.Remove(db.Agince.FirstOrDefault(w => w.Agince_ID == model.Id));
                        db.SaveChanges();
                        aganis_Car.Agince_ID = (model.Id);
                        aganis_Car.name      = model.UserName;
                        //aganis_Car.password = model.Password;
                        aganis_Car.phone_number = model.PhoneNumber;
                        aganis_Car.city         = model.city;
                        aganis_Car.street       = model.Street;
                        context.Agince.Add(aganis_Car);
                        context.SaveChanges();
                    }
                    else
                    {
                        aganis_Car.Agince_ID = (model.Id);
                        aganis_Car.name      = model.UserName;
                        // aganis_Car.password = model.Password;
                        aganis_Car.phone_number = model.PhoneNumber;
                        aganis_Car.city         = model.city;
                        aganis_Car.street       = model.Street;
                        context.Agince.Add(aganis_Car);
                        context.SaveChanges();
                    }
                }


                var user = new ApplicationUser {
                    UserName    = model.UserName,
                    Email       = model.Email,
                    Id          = model.Id,
                    PhoneNumber = model.PhoneNumber,
                    city        = model.city,
                    street      = model.Street
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");



                    this.UserManager.AddToRole(user.Id, model.Roles);
                    if (model.Roles == "Agince")
                    {
                        return(RedirectToAction("complete_data", "Aginces", new { id = user.Id }));
                    }
                    else if (model.Roles == "Client")
                    {
                        return(RedirectToAction("complete_data", "Clients", new { id = user.Id }));
                    }
                    else if (model.Roles == "Admin")
                    {
                        return(RedirectToAction("UsersWithRoles"));
                    }
                }

                if (!User.IsInRole("Admin"))
                {
                    ViewBag.Roles = new SelectList(context.Roles.Where(e => e.Name != "Admin").ToList(), "Name", "Name");
                }

                else
                {
                    ViewBag.Roles = new SelectList(context.Roles.Where(e => e.Name == "Admin").ToList(), "Name", "Name");
                };
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }