public string ProccessData(List<DataVote> data) { if (data != null && Session["IsVoted"] ==null) { List<Сandidate> candidates = new List<Сandidate>(); using (var db = new DbRepository(new dbname123Entities())) { candidates = db.GetСandidate().ToList(); foreach (var el in candidates) { if (data.Where(x => x.Id == el.Id && x.Category == el.Category).FirstOrDefault() != null) { if (el.Likes == null) { el.Likes = new int(); } el.Likes++; } } db.Save(); String name = (String)Session["UserEmail"]; var user = db.context.Users.Where(x => x.Email == name).FirstOrDefault(); user.IsVoted = new int(); user.IsVoted = 1; Session["IsVoted"] = true; db.Save(); } } return "true"; }
public String CheckUserSendMessage(User user) { try { String response = String.Empty; if (user != null) { using (var db = new DbRepository(new dbname123Entities())) { var existUser = db.context.Users .Where(x => x.FirstName == user.FirstName && x.SurName == user.SurName && x.Room == user.Room) .FirstOrDefault(); if (existUser != null) { if (existUser.IsVoted.HasValue) response = "IsVoted"; else { var existEmail = db.context.Users.Where(x => x.Email == user.Email && x.Id!=existUser.Id).FirstOrDefault(); if (existEmail != null) response = "ExistEmail"; else { existUser.Email = user.Email; db.UpdateUser(existUser); db.Save(); response = user.Email; } } } else { response = "NotExist"; } } } return response; } catch (Exception) { return String.Empty; } }
public void SendMessage(string email) { try { if (email != null) { using (var db = new DbRepository(new dbname123Entities())) { var existUser = db.context.Users .Where(x => x.Email == email) .FirstOrDefault(); if (existUser != null) { var mail = new EmailMessage(); mail.CreateMessage(email); var pass = mail.SendMessage(); existUser.Password = pass; db.Save(); } } } } catch (Exception) { } }