コード例 #1
0
        public ActionResult Create(User user)
        {
            if (ModelState.IsValid)
            {
                db.Users.Add(user);
                db.SaveChanges();

                UsersHelper.CreateUserASP(user.UserName, "User");

                if (user.PhotoFile != null)
                {
                    var folder  = "~/Content/Users";
                    var file    = string.Format("{0}-{1}.jpg", user.UserId, user.FullName);
                    var respose = FilesHelpers.UploadPhoto(user.PhotoFile, folder, file);

                    if (respose)
                    {
                        var pic = string.Format("{0}/{1}", folder, file);
                        //si respose es true, actualizamos el logo de la compania
                        user.Photo = pic;
                        //actalizamos la dv
                        db.Entry(user).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                }
                return(RedirectToAction("Index"));
            }

            ViewBag.CityId       = new SelectList(CombosHelpers.GetCities(), "CityId", "Name", user.CityId);
            ViewBag.CompanyId    = new SelectList(CombosHelpers.GetCompanies(), "CompanyId", "Name", user.CompanyId);
            ViewBag.DepartmentId = new SelectList(db.Departments, "DepartmentId", "Name", user.DepartmentId);
            return(View(user));
        }
コード例 #2
0
 public ActionResult Create()
 {
     ViewBag.CityId       = new SelectList(CombosHelpers.GetCities(), "CityId", "Name");
     ViewBag.CompanyId    = new SelectList(CombosHelpers.GetCompanies(), "CompanyId", "Name");
     ViewBag.DepartmentId = new SelectList(CombosHelpers.GetDepartments(), "DepartmentId", "Name");
     return(View());
 }
コード例 #3
0
        public ActionResult Edit(User user)
        {
            if (ModelState.IsValid)
            {
                byte[] imagenActual = null;

                HttpPostedFileBase FileBase = Request.Files[0];
                if (FileBase == null)
                {
                    imagenActual = db.Users.SingleOrDefault(t => t.UserID == user.UserID).Foto;
                }
                else
                {
                    WebImage image = new WebImage(FileBase.InputStream);
                    user.Foto = image.GetBytes();
                }
                db.Entry(user).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.CityID       = new SelectList(CombosHelpers.GetCities(user.DepartmentID), "CityID", "Name", user.CityID);
            ViewBag.CompanyID    = new SelectList(CombosHelpers.GetCompanies(), "CompanyID", "Name", user.CompanyID);
            ViewBag.DepartmentID = new SelectList(CombosHelpers.GetDepartments(), "DepartmentID", "Name", user.DepartmentID);
            return(View(user));
        }
コード例 #4
0
        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(CombosHelpers.GetCities(), "CityId", "Name", user.CityId);
            ViewBag.CompanyId    = new SelectList(CombosHelpers.GetCompanies(), "CompanyId", "Name", user.CompanyId);
            ViewBag.DepartmentId = new SelectList(CombosHelpers.GetDepartments(), "DepartmentId", "Name", user.DepartmentId);
            return(View(user));
        }
コード例 #5
0
        public ActionResult Create(User user)
        {
            if (ModelState.IsValid)
            {
                HttpPostedFileBase FileBase = Request.Files[0];
                WebImage           image    = new WebImage(FileBase.InputStream);
                user.Foto = image.GetBytes();
                db.Users.Add(user);
                db.SaveChanges();
                UsersHelper.CreateUserASP(user.UserName, "User");
                return(RedirectToAction("Index"));
            }

            ViewBag.CityID       = new SelectList(CombosHelpers.GetCities(user.DepartmentID), "CityID", "Name", user.CityID);
            ViewBag.CompanyID    = new SelectList(CombosHelpers.GetCompanies(), "CompanyID", "Name", user.CompanyID);
            ViewBag.DepartmentID = new SelectList(CombosHelpers.GetDepartments(), "DepartmentID", "Name", user.DepartmentID);
            return(View(user));
        }
コード例 #6
0
        public ActionResult Edit(User user)
        {
            if (ModelState.IsValid)
            {
                if (user.PhotoFile != null)
                {
                    var pic = string.Empty;

                    var folder  = "~/Content/Users";
                    var file    = string.Format("{0}-{1}.jpg", user.UserId, user.FullName);
                    var respose = FilesHelpers.UploadPhoto(user.PhotoFile, folder, file);

                    if (respose)
                    {
                        pic = string.Format("{0}/{1}", folder, file);
                        //si respose es true, actualizamos el logo de la compania
                        user.Photo = pic;
                    }
                }


                var db2         = new ECommerceContext();
                var currentUser = db2.Users.Find(user.UserId);
                if (currentUser.UserName != user.UserName)
                {
                    UsersHelper.UpdateUserName(currentUser.UserName, user.UserName);
                }
                db2.Dispose();

                //actalizamos la dv
                db.Entry(user).State = EntityState.Modified;
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }
            ViewBag.CityId       = new SelectList(CombosHelpers.GetCities(), "CityId", "Name", user.CityId);
            ViewBag.CompanyId    = new SelectList(CombosHelpers.GetCompanies(), "CompanyId", "Name", user.CompanyId);
            ViewBag.DepartmentId = new SelectList(db.Departments, "DepartmentId", "Name", user.DepartmentId);
            return(View(user));
        }