Beispiel #1
0
        // GET: Users/Create
        public ActionResult Create()
        {
            ViewBag.CityId =
                new SelectList(
                    ComBoxHelpers.
                    GetCities(),
                    "CityId",
                    "NameCity");

            ViewBag.CompanyId =
                new SelectList(
                    ComBoxHelpers.
                    GetCompanies(),
                    "CompanyId",
                    "NameCompany");

            ViewBag.StateId =
                new SelectList(
                    ComBoxHelpers.
                    GetStates(),
                    "StateId",
                    "NameState");

            return(View());
        }
        // GET: Cities/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(
                           HttpStatusCode.BadRequest));
            }

            var city = db.Cities.Find(id);

            if (city == null)
            {
                return(HttpNotFound());
            }

            ViewBag.StateId =
                new SelectList(
                    ComBoxHelpers.
                    GetStates(),
                    "StateId",
                    "NameState",
                    city.StateId);

            return(View(city));
        }
        // GET: Cities/Create
        public ActionResult Create()
        {
            ViewBag.StateId =
                new SelectList(
                    ComBoxHelpers.
                    GetStates(),
                    "StateId",
                    "NameState");

            return(View());
        }
        public ActionResult Edit(City city)
        {
            if (ModelState.IsValid)
            {
                db.Entry(city).State =
                    EntityState.Modified;

                try
                {
                    db.SaveChanges();

                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    if (ex.InnerException != null &&
                        ex.InnerException.
                        InnerException != null &&
                        ex.InnerException.
                        InnerException.Message.
                        Contains("_Index"))
                    {
                        ModelState.
                        AddModelError(
                            string.Empty,
                            "You Can't Add a New Record, Because There is Already One");
                    }
                    else
                    {
                        ModelState.
                        AddModelError(
                            string.Empty,
                            ex.Message);
                    }
                }
            }

            ViewBag.StateId =
                new SelectList(
                    ComBoxHelpers.
                    GetStates(),
                    "StateId",
                    "NameState",
                    city.StateId);

            return(View(city));
        }
        public ActionResult Create(Category category)
        {
            if (ModelState.IsValid)
            {
                db.Categories.Add(category);

                try
                {
                    db.SaveChanges();

                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    if (ex.InnerException != null &&
                        ex.InnerException.
                        InnerException != null &&
                        ex.InnerException.
                        InnerException.Message.
                        Contains("_Index"))
                    {
                        ModelState.
                        AddModelError(
                            string.Empty,
                            "You Can't Add a New Record, Because There is Already One");
                    }
                    else
                    {
                        ModelState.
                        AddModelError(
                            string.Empty,
                            ex.Message);
                    }
                }
            }

            ViewBag.CompanyId =
                new SelectList(
                    ComBoxHelpers.
                    GetCompanies(),
                    "CompanyId",
                    "NameCompany",
                    category.CompanyId);

            return(View(category));
        }
Beispiel #6
0
        // GET: Users/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(
                           HttpStatusCode.BadRequest));
            }

            var user = db.Users.Find(id);

            if (user == null)
            {
                return(HttpNotFound());
            }

            ViewBag.CityId =
                new SelectList(
                    ComBoxHelpers.
                    GetCities(),
                    "CityId",
                    "NameCity",
                    user.CityId);

            ViewBag.CompanyId =
                new SelectList(
                    ComBoxHelpers.
                    GetCompanies(),
                    "CompanyId",
                    "NameCompany",
                    user.CompanyId);

            ViewBag.StateId =
                new SelectList(
                    ComBoxHelpers.
                    GetStates(),
                    "StateId",
                    "NameState",
                    user.StateId);

            return(View(user));
        }
        public ActionResult Create(City city)
        {
            if (ModelState.IsValid)
            {
                db.Cities.Add(city);

                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            ViewBag.StateId =
                new SelectList(
                    ComBoxHelpers.
                    GetStates(),
                    "StateId",
                    "NameState",
                    city.StateId);

            return(View(city));
        }
        public ActionResult Edit(City city)
        {
            if (ModelState.IsValid)
            {
                db.Entry(city).State =
                    EntityState.Modified;

                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            ViewBag.StateId =
                new SelectList(
                    ComBoxHelpers.
                    GetStates(),
                    "StateId",
                    "NameState",
                    city.StateId);

            return(View(city));
        }
        public ActionResult Create(Company company)
        {
            if (ModelState.IsValid)
            {
                db.Companies.Add(company);

                try
                {
                    db.SaveChanges();

                    if (company.LogoFile != null)
                    {
                        var folder = "~/Content/Logos";

                        var file = string.Format("{0}.jpg",
                                                 company.CompanyId);

                        var response =
                            FilesHelpers.
                            UploadPhoto(
                                company.LogoFile,
                                folder, file);

                        if (response)
                        {
                            var pic =
                                string.Format("{0}/{1}",
                                              folder,
                                              file);

                            company.Logo = pic;

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

                            db.SaveChanges();
                        }
                    }

                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    if (ex.InnerException != null &&
                        ex.InnerException.
                        InnerException != null &&
                        ex.InnerException.
                        InnerException.Message.
                        Contains("_Index"))
                    {
                        ModelState.
                        AddModelError(
                            string.Empty,
                            "You Can't Add a New Record, Because There is Already One");
                    }
                    else
                    {
                        ModelState.
                        AddModelError(
                            string.Empty,
                            ex.Message);
                    }
                }
            }

            ViewBag.CityId =
                new SelectList(
                    ComBoxHelpers.
                    GetCities(),
                    "CityId",
                    "NameCity",
                    company.CityId);

            ViewBag.StateId =
                new SelectList(
                    ComBoxHelpers.
                    GetStates(),
                    "StateId",
                    "NameState",
                    company.StateId);

            return(View(company));
        }
Beispiel #10
0
        public ActionResult Edit(User user)
        {
            if (ModelState.IsValid)
            {
                if (user.PhotoFile != null)
                {
                    var folder = "~/Content/Photos";

                    var pic = string.Empty;

                    var file = string.Format("{0}.jpg", user.UserID);

                    var response =
                        FilesHelpers.
                        UploadPhoto(
                            user.PhotoFile,
                            folder,
                            file);

                    if (response)
                    {
                        pic = string.Format("{0}/{1}", folder, user.UserID);

                        user.Photo = pic;
                    }
                }

                var db2 = new CECommerceContext();

                var currentUser = db2.Users.Find(user.UserID);

                if (currentUser.UserName != null)
                {
                    UsersHelpers.UpdateUserName(currentUser.UserName, user.UserName);
                }

                db2.Dispose();

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

                try
                {
                    db.SaveChanges();

                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    if (ex.InnerException != null &&
                        ex.InnerException.
                        InnerException != null &&
                        ex.InnerException.
                        InnerException.Message.
                        Contains("_Index"))
                    {
                        ModelState.
                        AddModelError(
                            string.Empty,
                            "You Can't Add a New Record, Because There is Already One");
                    }
                    else
                    {
                        ModelState.
                        AddModelError(
                            string.Empty,
                            ex.Message);
                    }
                }
            }
            ViewBag.CityId =
                new SelectList(
                    ComBoxHelpers.
                    GetCities(),
                    "CityId",
                    "NameCity",
                    user.CityId);

            ViewBag.CompanyId =
                new SelectList(
                    ComBoxHelpers.
                    GetCompanies(),
                    "CompanyId",
                    "NameCompany",
                    user.CompanyId);

            ViewBag.StateId =
                new SelectList(
                    ComBoxHelpers.
                    GetStates(),
                    "StateId",
                    "NameState",
                    user.StateId);

            return(View(user));
        }