public static spiffaiwebEntities LoadDB() { spiffaiwebEntities entities = new spiffaiwebEntities(); entities.Configuration.LazyLoadingEnabled = false; entities.Configuration.EnsureTransactionsForFunctionsAndCommands = true; return entities; }
public static string AddEditUpdate(Update update) { spiffaiwebEntities db = new spiffaiwebEntities(); string response = ""; try { if (update.UpdateId > 0) { //Edit db.Entry(update).State = EntityState.Modified; db.SaveChanges(); response = "Succcess"; } else { //Create db.Updates.Add(update); db.SaveChanges(); response = "Success"; } } catch (Exception) { response = "Error"; throw; } return response; }
public static List<TeamMemberListingModel> GetTeamMemberListing() { var response = new List<TeamMemberListingModel>(); spiffaiwebEntities db = new spiffaiwebEntities(); var teamMembers = db.sp_GetTeamMemberListing(); foreach (var t in teamMembers) { var teamMember = new TeamMemberListingModel { TeamMemberId = t.TeamMemberId, TeamMemberFirstName = t.TeamMemberFirstName, TeamMemberLastName = t.TeamMemberLastName, TeamMemberDepartment = t.DepartmentName, TeamMemberTitle = t.TeamMemberTitle, TeamMemberAvatar = t.TeamMemberAvatar, CompanyEmail = t.CompanyEmail }; response.Add(teamMember); } return response; }
public static PollConfigurationFormModel SavePollConfiguration(PollConfigurationFormModel model) { var savedPoll = new PollConfigurationFormModel(); spiffaiwebEntities db = new spiffaiwebEntities(); try { var pollConfiguration = new Poll { TypeId = (int)model.TypeId, PollTitle = model.PollTitle, PollDetails = model.PollDetails, IsActive = model.IsActive, Deadline = model.Deadline, DeadlineDate = model.DeadlineDate, DeadlineTime = model.DeadlineTime, }; savedPoll.TypeId = model.TypeId; savedPoll.PollTitle = model.PollTitle; savedPoll.PollDetails = model.PollDetails; savedPoll.IsActive = model.IsActive; savedPoll.Deadline = model.Deadline; savedPoll.DeadlineDate = model.DeadlineDate; savedPoll.DeadlineTime = model.DeadlineTime; if (model.PollId > 0) { //Edit pollConfiguration.PollId = model.PollId; db.Entry(pollConfiguration).State = EntityState.Modified; db.SaveChanges(); savedPoll.PollId = pollConfiguration.PollId; } else { //Create db.Polls.Add(pollConfiguration); db.SaveChanges(); savedPoll.PollId = pollConfiguration.PollId; } } catch (Exception ex) { throw; } return savedPoll; }
public static PollOptionModel SavePollOptionConfiguration(PollOptionModel model) { PollOptionModel response = model; model.AlertType = AlertType.Error; spiffaiwebEntities db = new spiffaiwebEntities(); try { var option = new PollOption { PollId = model.PollId, PollOptionTitle = model.PollOptionTitle, PollOptionDescription = model.PollOptionDescription, PollOptionUrl = model.PollOptionUrl, }; if (model.PollOptionId > 0) { //Edit option.PollOptionId = model.PollOptionId; db.Entry(option).State = EntityState.Modified; db.SaveChanges(); model.AlertType = AlertType.Success; } else { //Create Poll Option db.PollOptions.Add(option); db.SaveChanges(); model.AlertType = AlertType.Success; response.PollOptionId = option.PollOptionId; //Add to VoteCount var voteCount = new PollVoteCount { PollId = model.PollId, PollOptionId = option.PollOptionId, PollOptionVoteTotal = 0 }; db.PollVoteCounts.Add(voteCount); db.SaveChanges(); } } catch (Exception) { throw; } return response; }
public static bool SavePollVoteForm(PollVoteFormModel model) { spiffaiwebEntities db = new spiffaiwebEntities(); bool success =false; try { //Save PollVote var voteModel = new PollVote { PollId = model.PollId, PollOptionId = (int)model.SelectedPollOptionId, UserId = (int)WebSecurity.CurrentUserId, VoteDate = (DateTime)DateTime.Now }; db.PollVotes.Add(voteModel); db.SaveChanges(); success = SavePollVoteCount(model.PollId, voteModel.PollOptionId); } catch (Exception ex) { throw; } return success; }
public static bool SavePollVoteCount(int pollId, int pollOptionId) { bool success = false; spiffaiwebEntities db = new spiffaiwebEntities(); //Update PollVoteCount PollVoteCountModel response = GetPollVoteCountModel(pollId, pollOptionId); if (response.PollVoteCountId > 0) { var voteCount = new PollVoteCount(); voteCount.PollVoteCountId = response.PollVoteCountId; voteCount.PollId = pollId; voteCount.PollOptionId = pollOptionId; voteCount.PollOptionVoteTotal = response.PollOptionVoteTotal; db.Entry(voteCount).State = EntityState.Modified; db.SaveChanges(); success = true; } else { //Add to VoteCount var voteCount = new PollVoteCount { PollId = pollId, PollOptionId = pollOptionId, PollOptionVoteTotal = 1 }; db.PollVoteCounts.Add(voteCount); db.SaveChanges(); success = true; } return success; }
public static PollVoteCountModel GetPollVoteCountModel(int pollId, int pollOptionId) { var response = new PollVoteCountModel(); spiffaiwebEntities db = new spiffaiwebEntities(); var pollVoteCount = (from p in db.PollVoteCounts where p.PollId == pollId && p.PollOptionId == pollOptionId select p).FirstOrDefault(); if (pollVoteCount != null) { response.PollVoteCountId = pollVoteCount.PollVoteCountId; response.PollOptionVoteTotal = pollVoteCount.PollOptionVoteTotal; response.PollOptionVoteTotal++; } return response; }
public ActionResult LostPassword(LostPasswordModel model) { if (ModelState.IsValid) { MembershipUser user; using (var context = new spiffaiwebEntities()) { var foundUserName = (from u in context.UserProfiles where u.Email == model.Email select u.UserName).FirstOrDefault(); if (foundUserName != null) { user = Membership.GetUser(foundUserName.ToString()); } else { user = null; } } if (user != null) { // Generate password token that will be used in the email link to authenticate user var token = WebSecurity.GeneratePasswordResetToken(user.UserName); // Generate the html link sent via email string resetLink = Url.Action("ResetPassword", "Account", new { rt = token }, "http"); // Email stuff string subject = "Password Reset at Spiffai.com"; string body = "You link: " + resetLink; string from = "*****@*****.**"; MailMessage message = new MailMessage(from, model.Email); message.Subject = subject; message.Body = body; SmtpClient client = new SmtpClient(); // Attempt to send the email try { client.Send(message); } catch (Exception e) { ModelState.AddModelError("", "Issue sending email: " + e.Message); } return RedirectToAction("LostPasswordSuccess", "Account"); } else // Email not found { ModelState.AddModelError("", "No user found by that email."); } } return View(model); }