public ActionResult Registration(UserViewModel user) { user.guid = Guid.NewGuid(); if (ModelState.IsValid && !repo.isEmailTaken(user.Email)) { var newUser = EntityModelMapper.ModelToEntity(user); repo.AddOrUpdate(newUser); if (Request.IsAjaxRequest()) { return(Content("Login")); } return(Redirect("/Auth/Login")); } ModelState.AddModelError("", "Something went wrong"); if (Request.IsAjaxRequest()) { return(Content("Invalid information!")); } return(View(user)); }
public ActionResult EditPicture(PictureViewModel model, HttpPostedFileBase file) { string pictureFolder = Server.MapPath("../../Images"); var path = string.Empty; var fileName = string.Empty; if (file != null && file.ContentLength > 0) { fileName = model.UserID + model.GalleryID + Path.GetFileName(file.FileName); path = Path.Combine(pictureFolder, fileName); file.SaveAs(path); model.Path = "~/Images/" + fileName; RemoveOldFileIfExists(model); } model.DateEdited = DateTime.Now; if (ModelState.IsValid) { var picToUpdate = EntityModelMapper.ModelToEntity(model); repo.AddOrUpdate(picToUpdate); return(RedirectToAction("Details", "Picture", model)); } ModelState.AddModelError("", "Couldn't update information"); return(View(model)); }
public ActionResult Index(AlbumModel album, string albumComment) { CommentModel commentModel = new CommentModel() { Comment = albumComment, DateCreated = DateTime.Now, Album = album, }; var commentEntity = EntityModelMapper.ModelToEntity(commentModel); CommentRepo.NewAlbumComment(album.AlbumModelId, commentEntity); return(View(AlbumRepo.GetAll())); }
public ActionResult Register(UserModel userModel) { if (ModelState.IsValid) { if (userModel != null) { //todo: create growl when user gets registered UserRepository.Add(EntityModelMapper.ModelToEntity(userModel)); return(RedirectToAction("Index", "Home")); } } // If we got this far, something failed, redisplay form return(View(userModel)); }
public ActionResult Create(GalleryViewModel model) { if (User.Identity.IsAuthenticated) { var identity = (ClaimsIdentity)User.Identity; int?userID = int.Parse(Helpers.GetSid(identity)); if (userID != null) { model.DateCreated = DateTime.Now; model.UserID = (int)userID; var entity = EntityModelMapper.ModelToEntity(model); repo.AddOrUpdate(entity); } return(RedirectToAction("Index", "Gallery")); } return(Redirect(Request.UrlReferrer.ToString())); }
public ActionResult NewComment(CommentViewModel model) { var identity = (ClaimsIdentity)User.Identity; var sid = identity.Claims.First(x => x.Type == ClaimTypes.Sid); model.UserID = int.Parse(sid.Value); model.DatePosted = DateTime.Now; if (ModelState.IsValid && User.Identity.IsAuthenticated) { var newComment = EntityModelMapper.ModelToEntity(model); repo.AddOrUpdate(newComment); return(Content("Comment added")); } return(Content("Couldn't add comment")); }
public ActionResult Create(PictureViewModel model, HttpPostedFileBase photo) { Thread.Sleep(5000); model.UserID = int.Parse(MVCLabb.Utilities.Helpers.GetSid(User.Identity)); model.DatePosted = DateTime.Now; string pictureFolder = Server.MapPath("~/Images"); var path = string.Empty; var fileName = string.Empty; if (photo != null && photo.ContentLength > 0) { fileName = model.UserID + model.GalleryID + Path.GetFileName(photo.FileName); if (!Helpers.IsFilePicture(fileName)) { return(Content("The file must be a picture in the format png, jpg or jpeg")); } path = Path.Combine(pictureFolder, fileName); photo.SaveAs(path); } else { return(Content("You must choose a file!")); } model.Path = "~/Images/" + fileName; if (ModelState.IsValid) { var newPicture = EntityModelMapper.ModelToEntity(model); repo.AddOrUpdate(newPicture); return(Content("Added picture to gallery!")); //return RedirectToAction("ViewGallery", "Gallery", new { id = model.GalleryID }); } return(Content("Something went wrong couldn't add the picture")); }
public ActionResult Create(AlbumModel albumModel) { try { int userId = albumModel.AlbumModelId; //TODO: userid and albumid the same? why? var albumEntity = EntityModelMapper.ModelToEntity(albumModel); //albumEntity.User = UserRepo.GetUser(userId); AlbumRepo.Add(albumEntity, userId);//adds new album to dbset(database) //create directory for new albums photos string newAlbumPath = Server.MapPath("~/UsersData/" + albumEntity.User.Username + "/" + albumEntity.Name); Directory.CreateDirectory(newAlbumPath); return(RedirectToAction("Index", "User")); } catch { return(View()); } }