Пример #1
0
 // GET: Users/Create
 public ActionResult Create()
 {
     ViewBag.CityId         = new SelectList(ComboHelper.GetCities(), "CityId", "Name");
     ViewBag.CompanyId      = new SelectList(ComboHelper.GetCompanys(), "CompanyId", "Name");
     ViewBag.DepartamentsId = new SelectList(ComboHelper.GetDepartaments(), "DepartamentsId", "Name");
     return(View());
 }
Пример #2
0
        public ActionResult Edit(User user)
        {
            if (ModelState.IsValid)
            {
                if (user.PhotoFile != null)
                {
                    var pic      = string.Empty;
                    var folder   = "~/Content/User";
                    var file     = string.Format("{0}.jpg", user.UserId);
                    var response = FilesHelper.UploadPhoto(user.PhotoFile, folder, file);

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


                db.Entry(user).State = EntityState.Modified;
                try
                {
                    var db2         = new ECommerceContext();
                    var currentUser = db2.Users.Find(user.UserId);
                    if (currentUser.Email != user.Email)
                    {
                        UserHelper.UsersHelper.UpdateUserName(currentUser.Email, user.Email);
                    }

                    db2.Dispose();
                    db.SaveChanges();

                    return(RedirectToAction("Index"));
                }
                catch (System.Exception ex)
                {
                    if (ex.InnerException != null &&
                        ex.InnerException.InnerException != null &&
                        ex.InnerException.InnerException.Message.Contains("_Index"))
                    {
                        ModelState.AddModelError(string.Empty, "Telefone ou email ja existentes !!");
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, ex.Message);
                    }

                    ViewBag.CityId         = new SelectList(ComboHelper.GetCities(), "CityId", "Name", user.CityId);
                    ViewBag.CompanyId      = new SelectList(ComboHelper.GetCompanys(), "CompanyId", "Name", user.CompanyId);
                    ViewBag.DepartamentsId = new SelectList(ComboHelper.GetDepartaments(), "DepartamentsId", "Name", user.DepartamentsId);
                    return(View(user));
                }
            }
            ViewBag.CityId         = new SelectList(ComboHelper.GetCities(), "CityId", "Name", user.CityId);
            ViewBag.CompanyId      = new SelectList(ComboHelper.GetCompanys(), "CompanyId", "Name", user.CompanyId);
            ViewBag.DepartamentsId = new SelectList(ComboHelper.GetDepartaments(), "DepartamentsId", "Name", user.DepartamentsId);
            return(View(user));
        }
Пример #3
0
        // GET: Users/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            User user = db.Users.Find(id);

            if (user == null)
            {
                return(HttpNotFound());
            }
            ViewBag.CityId         = new SelectList(ComboHelper.GetCities(), "CityId", "Name", user.CityId);
            ViewBag.CompanyId      = new SelectList(ComboHelper.GetCompanys(), "CompanyId", "Name", user.CompanyId);
            ViewBag.DepartamentsId = new SelectList(ComboHelper.GetDepartaments(), "DepartamentsId", "Name", user.DepartamentsId);
            return(View(user));
        }