// // GET: /Settings/ public ActionResult Save(SettingsModel sm) { user currentUser = Session["user"] as user; using(var conn = new ifollowdatabaseEntities4()) { currentUser = conn.users.First(u => u.id == currentUser.id); if (currentUser != null) { currentUser.firstName = sm.firstName; currentUser.lastName = sm.lastName; currentUser.city = sm.city; currentUser.country = sm.country; currentUser.birthdate = sm.birthDate; try { conn.SaveChanges(); } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } } } } return RedirectToAction("Settings","Wall"); }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { using (var entities = new ifollowdatabaseEntities4()) { user newUser = new user(); newUser.email = model.UserName; newUser.password = model.Password; newUser.registrationDate = DateTime.UtcNow.Date; char[] delimiters = { '@' }; string[] nameComponents = model.UserName.Split(delimiters); newUser.firstName = nameComponents[0]; newUser.lastName = @""; int count = entities.users.Count(); newUser.id = count + 1; entities.users.Add(newUser); try { entities.SaveChanges(); } catch (Exception e) { ModelState.AddModelError("", e); } return(RedirectToAction("Index", "Home")); } } // If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult Follow(string submit) { user currentUser = Session["user"] as user; long uid = (long)Convert.ToDouble(submit); using (var entities = new ifollowdatabaseEntities4()) { currentUser = entities.users.First(u => u.id == currentUser.id); follower fol = new follower(); fol.followedId = uid; fol.followerId = currentUser.id; entities.followers.Add(fol); try { entities.SaveChanges(); } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } } } return(RedirectToAction("Followers", "Wall")); }
public ActionResult Upload(UploadFileModel fileModel) { if (ModelState.IsValid) { image newImage = null; user currentUser = Session["user"] as user; if (fileModel != null && fileModel.File != null) { string timestamp = DateTime.UtcNow.ToString("yyyyMMddHHmmssffff") + ".png"; var path = Path.Combine(Server.MapPath("~/Images/UserPhotos"), timestamp); fileModel.File.SaveAs(path); fileModel.Path = timestamp; using (var entities = new ifollowdatabaseEntities4()) { newImage = new image(); newImage.isAvatar = false; newImage.isDeleted = false; newImage.url = timestamp; int count = entities.images.Count(); newImage.id = count + 1; newImage.ownerId = currentUser.id; entities.images.Add(newImage); try { entities.SaveChanges(); } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } } } } using (var entities = new ifollowdatabaseEntities4()) { post newPost = new post(); newPost.dateCreated = DateTime.UtcNow; int count = entities.posts.Count(); newPost.id = count + 1; if (newImage != null) { newPost.imageId = newImage.id; } newPost.ownerId = currentUser.id; newPost.message = fileModel.Message; newPost.rating = 0; newPost.isDeleted = false; entities.posts.Add(newPost); try { entities.SaveChanges(); } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } } } return(RedirectToAction("MainPage", "Wall")); } return(RedirectToAction("MainPage", "Wall")); }