/// <summary> /// /// </summary> /// <param name="pollId"></param> /// <param name="pollChoiceId"></param> public void AnswerPoll(long pollId, long pollChoiceId) { awPollChoice choice = (from l in _context.awPollChoices where l.pollId.Equals(pollId) && l.pollChoiceId.Equals(pollChoiceId) && l.awPoll.isEnabled && l.awPoll.awSite_Poll.isEnabled select l).FirstOrDefault <awPollChoice>(); if (choice == null) { throw new Exception(ErrorLibrary.ErrorMessage(ErrorLibrary.POLL.DOES_NOT_EXIST)); } int dateBetween = MiscLibrary.IsDateBetween(DateTime.Now, choice.awPoll.pubDate, choice.awPoll.pubEndDate); switch (dateBetween) { case -1: throw new Exception(ErrorLibrary.ErrorMessage(ErrorLibrary.POLL.NOT_PUBLISHED)); break; case 0: throw new Exception(ErrorLibrary.ErrorMessage(ErrorLibrary.POLL.EXPIRED)); break; } choice.numberOfVotes += 1; choice.lastBuildDate = DateTime.Now; _context.SubmitChanges(); }
/// <summary> /// /// </summary> /// <param name="pollChoiceId"></param> /// <returns></returns> public awPollChoice GetPollChoice(long pollChoiceId, string cultureCode) { if (pollChoiceId <= 0) { return(null); } var list = _context.GetTable <awPollChoice>() .Where(st => st.pollChoiceId.Equals(pollChoiceId)); if (list == null && list.ToList().Count() == 0) { return(null); } awPollChoice choice = list.FirstOrDefault(); //if site's culture code equals to cultureCode parameter if (String.IsNullOrEmpty(cultureCode) || choice.awPoll.awSite_Poll.cultureCode.ToLower() == cultureCode.ToLower()) { return(choice); } choice.title = _cultureLib.GetValue(cultureCode.ToLower(), choice.pollChoiceId, "awpollchoice", "title"); choice.description = _cultureLib.GetValue(cultureCode.ToLower(), choice.pollChoiceId, "awpollchoice", "description"); return(choice); }
/// <summary> /// /// </summary> /// <param name="pollId"></param> /// <param name="cultureCode"></param> /// <param name="description"></param> /// <returns></returns> public bool UpdatePollChoiceForCulture(long pollChoiceId, string cultureCode, string title, string description) { awPollChoice pollChoice = _context.awPollChoices.FirstOrDefault(st => st.pollChoiceId.Equals(pollChoiceId)); if (pollChoice == null) { return(false); } _cultureLib.UpdateValue(cultureCode, pollChoiceId, "awpollchoice", "title", title); _cultureLib.UpdateValue(cultureCode, pollChoiceId, "awpollchoice", "description", description); return(true); }
/// <summary> /// /// </summary> /// <param name="pollChoiceId"></param> /// <param name="title"></param> /// <param name="description"></param> /// <param name="sortOrder"></param> /// <returns></returns> public bool UpdatePollChoice(long pollChoiceId, string title, string description, int sortOrder) { awPollChoice pollChoice = _context.awPollChoices.FirstOrDefault(st => st.pollChoiceId.Equals(pollChoiceId)); if (pollChoice == null) { return(false); } pollChoice.title = title; pollChoice.description = description; pollChoice.sortOrder = sortOrder; pollChoice.lastBuildDate = DateTime.Now; _context.SubmitChanges(); return(true); }
/// <summary> /// /// </summary> /// <param name="pollId"></param> /// <param name="title"></param> /// <param name="description"></param> /// <param name="sortOrder"></param> /// <returns></returns> public long AddPollChoice(long pollId, string title, string description, int sortOrder) { long id = AWAPI_Common.library.MiscLibrary.CreateUniqueId(); awPollChoice pollChoice = new awPollChoice(); pollChoice.pollChoiceId = id; pollChoice.title = title; pollChoice.description = description; pollChoice.pollId = pollId; pollChoice.sortOrder = sortOrder; pollChoice.lastBuildDate = DateTime.Now; pollChoice.createDate = DateTime.Now; _context.awPollChoices.InsertOnSubmit(pollChoice); _context.SubmitChanges(); return(id); }