public ActionResult Create([Bind(Include = "Id,NazwaNagrody,Prestiż")] Nagrody nagrody) { if (ModelState.IsValid) { db.Nagrody.Add(nagrody); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(nagrody)); }
public ActionResult Create([Bind(Include = "Team_ID,Team_Name")] TEAMS tEAMS) { if (ModelState.IsValid) { db.TEAMS.Add(tEAMS); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tEAMS)); }
public ActionResult Create([Bind(Include = "Id,Gatunek")] Gatunki gatunki) { if (ModelState.IsValid) { db.Gatunki.Add(gatunki); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(gatunki)); }
public ActionResult Create([Bind(Include = "Id,Tytuł,Cena,IdGatunku,IdNagród,DataWydania")] Gry gry) { if (ModelState.IsValid) { db.Gry.Add(gry); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.IdGatunku = new SelectList(db.Gatunki, "Id", "Gatunek", gry.IdGatunku); ViewBag.IdNagród = new SelectList(db.Nagrody, "Id", "NazwaNagrody", gry.IdNagród); return(View(gry)); }
public ActionResult Create([Bind(Include = "Participants_ID,Season_ID,Driver_ID,Team_ID")] PARTICIPANTS pARTICIPANTS) { if (ModelState.IsValid) { db.PARTICIPANTS.Add(pARTICIPANTS); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Driver_ID = new SelectList(db.DRIVERS, "Driver_ID", "Driver_Name", pARTICIPANTS.Driver_ID); ViewBag.Season_ID = new SelectList(db.SEASONS, "Season_ID", "Year", pARTICIPANTS.Season_ID); ViewBag.Team_ID = new SelectList(db.TEAMS, "Team_ID", "Team_Name", pARTICIPANTS.Team_ID); return(View(pARTICIPANTS)); }
public void SetBet(string login, int race, string pos1, string pos2, string pos3, string time1) { using (ProjektEntities db = new ProjektEntities()) { using (var dbContextTransaction = db.Database.BeginTransaction()) { try { BETS itm = new BETS(); itm.User_ID = login; itm.Date = DateTime.Now.ToString(); itm.Race_ID = race; itm.Pos_1 = pos1; itm.Pos_2 = pos2; itm.Pos_3 = pos3; itm.Time_1 = time1; db.BETS.Add(itm); db.SaveChanges(); dbContextTransaction.Commit(); } catch { dbContextTransaction.Rollback(); } } } }
public ActionResult ForgotPassword(string Email) { //Verify Email ID //Generate Reset password link //Send Email string message = ""; bool status = false; using (ProjektEntities dc = new ProjektEntities()) { var account = dc.Users.Where(a => a.email == Email).FirstOrDefault(); if (account != null) { //Send email for reset password string resetCode = Guid.NewGuid().ToString(); SendVerificationLinkEmail(account.email, resetCode, "ResetPassword"); account.ResetPasswordCode = resetCode; //This line I have added here to avoid confirm password not match issue , as we had added a confirm password property //in our model class in part 1 dc.Configuration.ValidateOnSaveEnabled = false; dc.SaveChanges(); message = "Reset password link has been sent to your email"; } else { message = "Account not found"; } } ViewBag.Message = message; return(View()); }
public ActionResult AddToPrivate(Albums album, int id) { HomeModel homeModel = new HomeModel(); List <Comments> pictureComments = new List <Comments>(); var currentUserId = UserId(User.Identity.Name); using (ProjektEntities context = new ProjektEntities()) { PicturesAlbums picturesAlbums = new PicturesAlbums { pictures_id = id, album_id = album.id }; context.PicturesAlbums.Add(picturesAlbums); context.SaveChanges(); var comments = from c in context.Comments join u in context.Users on c.id_user equals u.id into ps where c.id_picture == id select new { Comment = c, Users = ps }; foreach (var comment in comments) { pictureComments.Add(comment.Comment); } homeModel.pictureComments = pictureComments; } return(PartialView("Comment", homeModel)); }
public ActionResult Delete(int picId) { using (ProjektEntities context = new ProjektEntities()) { var picture = context.Pictures.Where(a => a.id == picId).FirstOrDefault(); var pical = context.PicturesAlbums.Where(a => a.pictures_id == picId).ToList(); var comments = context.Comments.Where(a => a.id_picture == picId).ToList(); foreach (Comments comment in comments) { context.Comments.Remove(comment); } foreach (PicturesAlbums p in pical) { context.PicturesAlbums.Remove(p); } context.Pictures.Remove(picture); context.SaveChanges(); } HomeModel homeModel = new HomeModel(); IndexView(homeModel); ViewBag.Deleted = "true"; ViewBag.msg = "Zdjęcie zostało usunięte"; return(RedirectToAction("Index", "Home")); }
public ActionResult Comment(Comments Comment, int id) { HomeModel homeModel = new HomeModel(); List <Comments> pictureComments = new List <Comments>(); var currentUserId = UserId(User.Identity.Name); using (ProjektEntities context = new ProjektEntities()) { Comments Comment2 = new Comments { text = Comment.text, id_user = currentUserId, id_picture = id }; context.Comments.Add(Comment2); context.SaveChanges(); var comments = from c in context.Comments join u in context.Users on c.id_user equals u.id into ps where c.id_picture == id select new { Comment = c, Users = ps }; foreach (var comment in comments) { pictureComments.Add(comment.Comment); } homeModel.pictureComments = pictureComments; } return(PartialView("Comment", homeModel)); }
public ActionResult ResetPassword(ResetPasswordModel model) { var message = ""; if (ModelState.IsValid) { using (ProjektEntities dc = new ProjektEntities()) { var user = dc.Users.Where(a => a.ResetPasswordCode == model.ResetCode).FirstOrDefault(); if (user != null) { user.password = Crypto.Hash(model.NewPassword); user.ResetPasswordCode = ""; dc.Configuration.ValidateOnSaveEnabled = false; dc.SaveChanges(); message = "New password updated successfully"; } } } else { message = "Something is invalid"; } ViewBag.Message = message; return(View(model)); }
public ActionResult DeleteUser(string username) { List <Users> userList = new List <Users>(); using (ProjektEntities context = new ProjektEntities()) { var user = context.Users.Where(a => a.username == username).FirstOrDefault(); var comment = context.Comments.Where(a => a.id_user == user.id).ToList(); context.Users.Remove(user); foreach (Comments com in comment) { context.Comments.Remove(com); } context.SaveChanges(); userList = context.Users.ToList(); } foreach (Users user in userList) { user.RoleName = GetRoleName(user.role_id); } return(View("UserList", userList)); }
public ActionResult Zapros(string userID) { var db = new ProjektEntities(); var friend = from i in db.FRIENDS where i.User_ID == User.Identity.Name join us in db.USER on i.Friend_ID equals us.User_ID where us.Is_Exists == true select new { us.User_ID, us.Image }; var mod = new FriendsListView { ListFriends = new List <FriendsView>(), ListSearch = new List <FriendsView>() }; foreach (var x in friend) { mod.ListFriends.Add(new FriendsView { UserID = x.User_ID, imageData = x.Image }); } USER user = db.USER.Find(userID); /* INVITATIONS invitation = new INVITATIONS(); * invitation.Accept = false; * invitation.From_ID = User.Identity.Name; * invitation.To_ID = userID; * db.INVITATIONS.Add(invitation);*/ FRIENDS newFriend = new FRIENDS(); newFriend.Friend_ID = userID; newFriend.User_ID = User.Identity.Name; db.FRIENDS.Add(newFriend); db.SaveChanges(); newFriend.User_ID = userID; newFriend.Friend_ID = User.Identity.Name; db.FRIENDS.Add(newFriend); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult VerifyAge(Pesel pesel) { if (pesel.PeselNumber == null || pesel.BirthDate == null) { return(View()); } else { var currentUserId = UserId(User.Identity.Name); List <Users> userList = new List <Users>(); IPeselValidator peselValidator = new PeselValidator(); bool checkPesel = peselValidator.ValidatePesel(pesel.PeselNumber); bool checkPeselAndAge = false; if (checkPesel == false) { ViewBag.peselError = "Podany pesel jest niepoprawny"; return(View()); } if (peselValidator.ValidateAge(pesel.BirthDate)) { checkPeselAndAge = peselValidator.ValidatePeselAndBirthDate(pesel.PeselNumber, pesel.BirthDate); } if (checkPeselAndAge) { using (ProjektEntities context = new ProjektEntities()) { var user = context.Users.Where(a => a.id == currentUserId).FirstOrDefault(); user.email = user.email; user.username = user.username; user.ConfirmPassword = user.password; user.role_id = 3; context.SaveChanges(); } return(RedirectToAction("Index", "Home")); } else { ViewBag.peselError = "Podany pesel i data nie zgadzają się ze sobą"; return(View()); } } }
public ActionResult usun() { ProjektEntities db = new ProjektEntities(); var remove = db.MEMBERSHIPS.Where(a => a.User_ID == User.Identity.Name).ToList(); foreach (var vp in remove) { if (vp.Group_Name == MyStaticValues.groupname) { db.MEMBERSHIPS.Remove(vp); } } db.SaveChanges(); return(RedirectToAction("zarzadzaj")); }
public ActionResult Post(Comments Comment, Pictures Picture) { var currentUserId = UserId(User.Identity.Name); using (ProjektEntities context = new ProjektEntities()) { Comments Comment2 = new Comments { text = Comment.text, id_user = currentUserId, id_picture = Picture.id }; context.Comments.Add(Comment2); context.SaveChanges(); } return(PartialView("Comment")); }
public ActionResult Upload(HttpPostedFileBase file, Pictures Picture) { var currentUserId = UserId(User.Identity.Name); if (file != null && Picture.title != null) { string pic = System.IO.Path.GetFileName(file.FileName); string path = System.IO.Path.Combine( Server.MapPath("~/UserPictureImages/"), pic); string pathDB = pic; // file is uploaded file.SaveAs(path); using (ProjektEntities context = new ProjektEntities()) { Pictures Picture2 = new Pictures { AlbumId = Picture.AlbumId, title = Picture.title, description = Picture.description, img = pic, id_user = currentUserId, }; context.Pictures.Add(Picture2); PicturesAlbums pical = new PicturesAlbums { album_id = Picture2.AlbumId, pictures_id = Picture2.id }; context.PicturesAlbums.Add(pical); context.SaveChanges(); } return(RedirectToAction("Index", "Home")); } else { Pictures PictureModel = new Pictures(); using (ProjektEntities context = new ProjektEntities()) { PictureModel.AlbumCollection = context.Albums.ToList <Albums>(); } return(View("Upload", PictureModel)); } }
public ActionResult AddAlbum(Albums album) { if (album.album_name == null) { return(View()); } var currentUserId = UserId(User.Identity.Name); using (ProjektEntities context = new ProjektEntities()) { album.visibility = 0; album.id_user = currentUserId; context.Albums.Add(album); context.SaveChanges(); } ViewBag.cat = album.album_name; return(RedirectToAction("Index", "Home")); }
public void SetLogIn0(string login) { using (ProjektEntities db = new ProjektEntities()) { using (var dbContextTransaction = db.Database.BeginTransaction()) { try { USER us = db.USER.Find(login); us.Is_Log = false; db.SaveChanges(); dbContextTransaction.Commit(); } catch { dbContextTransaction.Rollback(); } } } }
public void AddUserAccount(UserSignUpView newUser) // dodanie użytkownika { using (ProjektEntities db = new ProjektEntities()) { MD5 md5Hash = MD5.Create(); USER user = new USER(); user.User_ID = newUser.Login; user.Password = GetMd5Hash(md5Hash, newUser.Password); user.e_mail = newUser.Email; user.Total_score = 0; user.Is_Admin = false; user.Is_Exists = true; user.Is_Log = true; user.Date_join = DateTime.Now; USER admin = db.USER.Find("Admin"); user.Image = admin.Image; db.USER.Add(user); db.SaveChanges(); } }
public void ChangeDescription(ProfileView user, string login) { using (ProjektEntities db = new ProjektEntities()) { using (var dbContextTransaction = db.Database.BeginTransaction()) { try { USER us = db.USER.Find(login); us.Description = user.description; db.SaveChanges(); dbContextTransaction.Commit(); } catch { dbContextTransaction.Rollback(); } } } }
public void ChangeEmail(UserSettingView user, string login) { using (ProjektEntities db = new ProjektEntities()) { using (var dbContextTransaction = db.Database.BeginTransaction()) { try { USER us = db.USER.Find(login); us.e_mail = user.emailView.newEmail; db.SaveChanges(); dbContextTransaction.Commit(); } catch { dbContextTransaction.Rollback(); } } } }
public void DeleteUser(UserSettingView user, string login) { using (ProjektEntities db = new ProjektEntities()) { using (var dbContextTransaction = db.Database.BeginTransaction()) { try { USER us = db.USER.Find(login); us.Is_Exists = false; us.Is_Admin = false; us.Is_Log = false; db.SaveChanges(); dbContextTransaction.Commit(); } catch { dbContextTransaction.Rollback(); } } } }
public void ChangePassword(UserSettingView user, string login) { using (ProjektEntities db = new ProjektEntities()) { using (var dbContextTransaction = db.Database.BeginTransaction()) { try { MD5 md5Hash = MD5.Create(); USER us = db.USER.Find(login); us.Password = GetMd5Hash(md5Hash, user.passwordView.Password); db.SaveChanges(); dbContextTransaction.Commit(); } catch { dbContextTransaction.Rollback(); } } } }
public ActionResult VerifyAccount(string id) { bool Status = false; using (ProjektEntities dc = new ProjektEntities()) { dc.Configuration.ValidateOnSaveEnabled = false; // This line I have added here to avoid // Confirm password does not match issue on save changes var v = dc.Users.Where(a => a.ActivationCode == new Guid(id)).FirstOrDefault(); if (v != null) { v.IsEmailVerified = true; dc.SaveChanges(); Status = true; } else { ViewBag.Message = "Invalid Request"; } } ViewBag.Status = Status; return(View()); }
public ActionResult wyslij(MessageListGroupView messageListGroupView) { ProjektEntities db = new ProjektEntities(); var mod = new MessageListGroupView { ListGroupMessage = new List <MessageGroupView>(), }; var message = from m in db.Group_mesage where (m.Group_Name == MyStaticValues.groupname) orderby m.Group_chat_ID select new { m.from_user, m.message, m.Group_Name }; foreach (var item in message) { mod.ListGroupMessage.Add(new MessageGroupView { fromUser = item.from_user, message = item.message, groupname = item.Group_Name, }); } Group_mesage newMessage = new Group_mesage(); newMessage.from_user = User.Identity.Name; newMessage.message = messageListGroupView.newMessageContent; newMessage.Group_Name = MyStaticValues.groupname; db.Group_mesage.Add(newMessage); db.SaveChanges(); return(RedirectToAction("Index", new { groupName = MyStaticValues.groupname })); }
public ActionResult EditUser(Users userModel, int userId, string userPassword) { List <Users> userList = new List <Users>(); using (ProjektEntities context = new ProjektEntities()) { var user = context.Users.Where(a => a.id == userId).FirstOrDefault(); user.email = userModel.email; user.username = userModel.username; user.role_id = userModel.role_id; user.ConfirmPassword = user.password; context.SaveChanges(); userList = context.Users.ToList(); } foreach (Users user in userList) { user.RoleName = GetRoleName(user.role_id); } return(View("UserList", userList)); }
public ActionResult Stworz_wyscig([Bind(Include = "Race_ID,Season_ID,Track,Date,Pos_1,Time_1,Pos_2,Pos_3")] RACES rACES) { if (ModelState.IsValid) { db.RACES.Add(rACES); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Season_ID = new SelectList(db.SEASONS, "Season_ID", "Year", rACES.Season_ID); ViewBag.Pos_1 = new SelectList(db.DRIVERS, "Driver_ID", "Driver_Name", rACES.Pos_1); ViewBag.Pos_2 = new SelectList(db.DRIVERS, "Driver_ID", "Driver_Name", rACES.Pos_2); ViewBag.Pos_3 = new SelectList(db.DRIVERS, "Driver_ID", "Driver_Name", rACES.Pos_3); ViewBag.Time_1 = new SelectList(db.DRIVERS, "Driver_ID", "Driver_Name", rACES.Time_1); return(View(rACES)); }
public ActionResult wyslij(MessageListView messageListView) { if (string.IsNullOrWhiteSpace(messageListView.newMessageContent)) // blokada przy wysylaniu pustej wiadomosci { return(RedirectToAction("Index", new { userID = userTo })); } ProjektEntities db = new ProjektEntities(); var mod = new MessageListView { ListMessage = new List <MessageView>(), ListUsersMessage = new List <MessageView>() }; var message = from m in db.MESSAGES where (m.Message_From == User.Identity.Name && m.Message_To == userTo) || (m.Message_From == userTo && m.Message_To == User.Identity.Name) orderby m.Message_ID select new { m.Message_From, m.Message_To, m.Content, m.Message_ID, m.Date }; foreach (var item in message) { mod.ListMessage.Add(new MessageView { fromUser = item.Message_From, toUser = item.Message_To, content = item.Content, messageID = item.Message_ID, date = item.Date }); } var listUser = db.MESSAGES.Where(m => m.Message_From == User.Identity.Name) .GroupBy(p => p.Message_To, (a, b) => b.OrderByDescending(e => e.Message_ID)).Select(s => s.FirstOrDefault()); foreach (var item in listUser) { mod.ListUsersMessage.Add(new MessageView { toUser = item.Message_To, date = item.Date }); } var listUser1 = db.MESSAGES.Where(m => m.Message_To == User.Identity.Name && m.Message_From != User.Identity.Name) .GroupBy(p => p.Message_From, (a, b) => b.OrderByDescending(e => e.Message_ID)).Select(s => s.FirstOrDefault()); foreach (var item in listUser1) { mod.ListUsersMessage.Add(new MessageView { toUser = item.Message_From, date = item.Date }); } for (int i = 0; i < mod.ListUsersMessage.Count; i++) { for (int j = i + 1; j < mod.ListUsersMessage.Count; j++) { System.Diagnostics.Debug.WriteLine("i " + mod.ListUsersMessage[i].toUser + " j " + mod.ListUsersMessage[j].toUser); if (mod.ListUsersMessage[i].toUser == mod.ListUsersMessage[j].toUser) { mod.ListUsersMessage.Remove(mod.ListUsersMessage[j]); } } } if (userTo == null) // mozliwosc napisania do samego siebie { userTo = User.Identity.Name; } MESSAGES newMessage = new MESSAGES(); newMessage.Message_From = User.Identity.Name; newMessage.Message_To = userTo; newMessage.Content = messageListView.newMessageContent; newMessage.Date = DateTime.Now; db.MESSAGES.Add(newMessage); db.SaveChanges(); return(RedirectToAction("Index", new { userID = userTo })); // przekazanie userTo do funkcji Index }
public ActionResult Registration([Bind(Exclude = "IsEmailVerified,ActivationCode")] Users user) { bool Status = false; string message = ""; // // Model Validation if (ModelState.IsValid) { #region //Email is already Exist var isExist = IsEmailExist(user.email); if (isExist) { ModelState.AddModelError("EmailExist", "Email already exist"); return(View(user)); } #endregion #region Generate Activation Code user.ActivationCode = Guid.NewGuid(); #endregion #region Password Hashing user.password = Crypto.Hash(user.password); user.ConfirmPassword = Crypto.Hash(user.ConfirmPassword); // #endregion user.IsEmailVerified = false; #region Save to Database using (ProjektEntities dc = new ProjektEntities()) { try { user.role_id = 1; dc.Users.Add(user); dc.SaveChanges(); } catch (Exception exception) { Console.WriteLine(exception); } //Send Email to User SendVerificationLinkEmail(user.email, user.ActivationCode.ToString()); message = " Registration successfully done. Account activation link " + " has been sent to your Email address: " + user.email; Status = true; } #endregion } else { message = "Invalid Request"; } ViewBag.Message = message; ViewBag.Status = Status; return(View(user)); }