public ActionResult AddPost(AddPostViewModel model, HttpPostedFileBase upload) { try { if (!ModelState.IsValid) return View(model); var pic = new AddPhotos(); var pathPic = pic.AddImage(upload, Server.MapPath("~/images/Posts/"), "~/images/Posts/"); var entity = Mapper.Map<AddPostViewModel, Post>(model); var userInSystem = User.Identity.Name; var user = _managerUser.GetUserByIEmail(userInSystem); entity.id_user = user.Id; entity.date = DateTime.Now; entity.description = model.Description; entity.Photo = new Photo { name = pathPic }; _managerPost.Add(entity); return RedirectToAction("MyPage", "Profile"); } catch (Exception) { return View(); } }
public ActionResult EditProfile(EditProfileViewModel model, HttpPostedFileBase upload) { try { if (!ModelState.IsValid) return View(model); var user = _managerUser.GetUserById(model.Id); string path = null; string pathPic = user.Photo.name; if (upload != null && upload.ContentLength > 0) { var pic = new AddPhotos(); pathPic = pic.AddImage(upload, Server.MapPath("~/images/UploadImages/"), "~/images/UploadImages/"); } user = Mapper.Map<EditProfileViewModel, User>(model,user); user.Photo.name = pathPic; return RedirectToAction("MyPage", "Profile"); } catch (Exception) { return View(); } }
public ActionResult Registration(RegisterViewModel model, HttpPostedFileBase upload) { try { if (!ModelState.IsValid) return View(model); var pic = new AddPhotos(); var pathPic = pic.AddImage(upload, Server.MapPath("~/images/UploadImages/"), "~/images/UploadImages/"); var entity = Mapper.Map<RegisterViewModel, User>(model); var user = _manager.GetUserByIEmail(model.Email); if (user != null) throw new Exception(Resource.EmailExist); var salt = PasswordHashing.PasswordHashing.GenerateSaltValue(); var pass = PasswordHashing.PasswordHashing.HashPassword(entity.password, salt); entity.password_salt = salt; entity.password = pass; entity.Photo = new Photo { name = pathPic }; _manager.Add(entity); entity.Useres = new List<UserInRoles>() {new UserInRoles() {id_roles = 2, id_user = entity.Id}}; _manager.Update(entity); var url = Url.Action("ConfirmEmail", "Account", new { Token = entity.Id, Email = entity.email }, Request.Url.Scheme); _manager.SentConfirmMail(entity, url); return RedirectToRoute("AfterRegistration"); } catch (Exception e) { model.Error = e.Message; return View(model); } }