public ActionResult UserPage(string login)
        {
            UserVM model;
            try
            {
                model = new UserVM(User);
            }
            catch
            {
                return RedirectToAction("Login", "Account");
            }

            if (login == string.Empty)
            {
                if (model.User == null)
                {
                    return RedirectToAction("Login", "Account");
                }
                return Redirect(@"/" + model.User.Login);
            }
            else
            {
                model.User = model.GetUserByLogin(login);
                var dir = Directory.GetFiles(HttpContext.Server.MapPath("~/WebImages/"));
                var toDelete = (from items in dir where items.Contains(model.User.Id.ToString()) select items).ToList();
                for (int i = 0; i < toDelete.Count(); i++)
                {
                    System.IO.File.Delete(toDelete[i]);
                }
            }

            if (model.User != null)
            {
                return View("Profile", model);
            }
            else
                return HttpNotFound();
        }
        public ActionResult MyProfileEdit(UserVM user, SkillsVM skillVM, HttpPostedFileBase Image, string WebcamImage)
        {
            if (WebcamImage != "null" && WebcamImage != string.Empty)
            {
                var path = HttpContext.Server.MapPath("~/WebImages/" + WebcamImage + ".jpg");
                user.Avatar = System.IO.File.ReadAllBytes(path);
            }

            if (Image != null && !IsImage(Image))
            {
                return Json(new { result = "Error", message = "Wrong image" });
            }
            if (ModelState.IsValid)
            {

                if (Image != null)
                {
                    using (var binaryReader = new BinaryReader(Image.InputStream))
                    {
                        user.Avatar = binaryReader.ReadBytes(Image.ContentLength);
                    }
                }

                var model = new UserVM(User, user, skillVM);
                System.IO.File.Delete(HttpContext.Server.MapPath("~/WebImages/" + WebcamImage + ".jpg"));
                model.SaveChanges();
                return Json(new { result = "Redirect", url = "/" + model.User.Login });
            }
            else
            {
                return Json(new { result = "Error", message = ModelState.Values.SelectMany(v => v.Errors).FirstOrDefault().ErrorMessage });
            }
        }
 public ActionResult ViewImage(string id)
 {
     UserVM item;
     try
     {
         item = new UserVM(id);
         byte[] buffer = item.Avatar;
         return File(buffer, "image/jpg", string.Format("{0}.jpg", id));
     }
     catch
     {
         return new EmptyResult();
     }
 }
 public ActionResult MyProjects()
 {
     var model = new UserVM(User);
     return View("MyProjects", model);
 }
Exemple #5
0
 public UserVM(IPrincipal user, UserVM editedUser, SkillsVM skill) : this(user)
 {
     _editedUser = editedUser;
     _editedSkills = skill;
 }