Exemplo n.º 1
0
        public ActionResult UploadAvatar(EditUserModel model)
        {
            var user = db.Users.Find(Membership.GetUser(model.Username).ProviderUserKey);

            //Check if all simple data annotations are valid
            if (ModelState.IsValid)
            {
                //Prepare the needed variables
                Bitmap original = null;
                var name = "newimagefile";
                var errorField = string.Empty;

                if (model.IsUrl)
                {
                    errorField = "Url";
                    name = user.Username;
                    original = GetImageFromUrl(model.Url);
                }

                else if (model.File != null) // model.IsFile
                {
                    errorField = "File";
                    name = user.Username;
                    original = Bitmap.FromStream(model.File.InputStream) as Bitmap;
                }

                //If we had success so far
                if (original != null)
                {
                    var img = CreateImage(original, model.X, model.Y, model.Width, model.Height);

                    //Demo purposes only - save image in the file system
                    var fn = Server.MapPath("~/Content/avatars/" + name + ".png");
                    img.Save(fn, System.Drawing.Imaging.ImageFormat.Png);

                    //Add the Image Name to the USer's Avatar Field
                    user.avatar = name;
                    db.SaveChanges();

                    //Redirect to index
                    return RedirectToAction("Edit", "User", new { id = user.UserId });
                }
                else //Otherwise we add an error and return to the (previous) view with the model data
                    ModelState.AddModelError(errorField, "Your upload did not seem valid. Please try again using only correct images!");

            }

            return RedirectToAction("Edit", "User", new { id = user.UserId });
        }
Exemplo n.º 2
0
        public ActionResult Edit(EditUserModel user)
        {
            if (ModelState.IsValid)
            {
                Entities.User usr = db.Users.Find(user.UserId);

                usr.Email = user.Email;
                usr.Username = user.Username;
                usr.IsApproved = user.IsApproved;
                usr.dci_nummer = user.dci_nummer;

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

                db.SaveChanges();

                return RedirectToAction("Index");
            }
            return View(user);
        }
Exemplo n.º 3
0
 public ActionResult Edit(Guid id)
 {
     User tUser = db.Users.Find(id);
     if (tUser != null)
     {
         EditUserModel user = new EditUserModel { UserId = id, Username = tUser.Username, Email = tUser.Email, IsApproved = tUser.IsApproved, dci_nummer = tUser.dci_nummer, avatar = tUser.avatar };
         return View(user);
     }
     return View(new EditUserModel());
 }