public ActionResult Edit([Bind(Include = "ID,Name,NumberOfWinners,NumberOfVoters")] Voting voting) { if (ModelState.IsValid) { List <Vote> votes = db.Votes.Where(v => v.VotingId == voting.ID).ToList(); if (votes.Count < voting.NumberOfVoters) { int difference = voting.NumberOfVoters - votes.Count; for (int i = 0; i < difference; i++) { string code; do { code = ""; for (int j = 0; j < 6; j++) { int choice = random.Next(3); switch (choice) { case 0: code += (char)random.Next(48, 58); break; case 1: code += (char)random.Next(65, 91); break; case 2: code += (char)random.Next(97, 123); break; default: break; } } } while (db.Votes.FirstOrDefault(v => v.Code == code) != null); Vote vote = new Vote() { Voting = voting, Code = code }; db.Votes.Add(vote); } } else { int difference = votes.Count - voting.NumberOfVoters; for (int i = 0; i < difference; i++) { db.Votes.Remove(votes[votes.Count - 1]); votes.Remove(votes[votes.Count - 1]); } } db.Entry(voting).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Details/" + voting.ID)); } return(View(voting)); }
public async Task <PartialViewResult> Vote(bool theUpVote, int?id, int channelID, string userName) { if (id == null) { return(PartialView()); } ChannelVote solutionVote = await db.ChannelVotes.FindAsync(channelID); if (solutionVote == null) { solutionVote = new ChannelVote(); solutionVote.CreationDate = DateTime.Now; solutionVote.Channel = await db.Channels.FindAsync(channelID); solutionVote.ChannelID = channelID; solutionVote.UserID = userName; } else { solutionVote.upVote = theUpVote; db.Entry(solutionVote).State = EntityState.Modified; } await db.SaveChangesAsync(); return(PartialView(solutionVote)); }
public async void ChangeVote(int?id) { IdeaVote ideaVote = await db.IdeaVotes.FindAsync(id); ideaVote.upVote = !ideaVote.upVote; db.Entry(ideaVote).State = EntityState.Modified; await db.SaveChangesAsync(); }
public async Task <TEntity> UpdateAsync(TEntity entity) { _votingContext.Entry(entity).State = EntityState.Modified; await _votingContext.SaveChangesAsync(); return(entity); }
public ActionResult Edit(Candidate candidate) { if (ModelState.IsValid) { db.Entry(candidate).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Details/" + candidate.VotingId, "Votings")); } ViewBag.VotingId = candidate.VotingId; return(View(candidate)); }
public async Task <ActionResult> Edit([Bind(Include = "CompanyID,CompanyName,Description")] Company company) { if (ModelState.IsValid) { db.Entry(company).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(company)); }
public async Task <ActionResult> Edit([Bind(Include = "CommentID,UserID,UserComment,CreationDate,BusinessChannelID")] IdeaComment ideaComment) { if (ModelState.IsValid) { db.Entry(ideaComment).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.BusinessChannelID = new SelectList(db.BusinessChannels, "BusinessChannelID", "Title", ideaComment.BusinessChannelID); return(View(ideaComment)); }
public async Task <ActionResult> Edit([Bind(Include = "BusinessChannelID,CategoryID,Title,Description,CreationDate")] BusinessChannel businessChannel) { if (ModelState.IsValid) { db.Entry(businessChannel).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.CategoryID = new SelectList(db.Categories, "CategoryID", "Title", businessChannel.CategoryID); return(View(businessChannel)); }
public async Task <ActionResult> Edit([Bind(Include = "ProblemID,UserID,ChannelID,Title,Description")] Problem problem) { if (ModelState.IsValid) { db.Entry(problem).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.ChannelID = new SelectList(db.Channels, "ChannelID", "Title", problem.ChannelID); return(View(problem)); }
public async Task <ActionResult> Edit([Bind(Include = "HoursOfOperationID,DayOfWeek,TimeOpen,LocationID")] HoursOfOperation hoursOfOperation) { if (ModelState.IsValid) { db.Entry(hoursOfOperation).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.LocationID = new SelectList(db.Locations, "LocationID", "StreetAddress1", hoursOfOperation.LocationID); return(View(hoursOfOperation)); }
public async Task <ActionResult> Edit([Bind(Include = "LocationID,StreetAddress1,StreetAddress2,ZipCode,City,State,Phone,website,CompanyID")] Location location) { if (ModelState.IsValid) { db.Entry(location).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.CompanyID = new SelectList(db.Companies, "CompanyID", "CompanyName", location.CompanyID); return(View(location)); }
public async Task <ActionResult> Edit([Bind(Include = "VoteID,UserID,upVote,CreationDate,SolutionID")] IdeaVote ideaVote) { if (ModelState.IsValid) { db.Entry(ideaVote).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.SolutionID = new SelectList(db.Ideas, "IdeaID", "UserID", ideaVote.SolutionID); return(View(ideaVote)); }
public async Task <ActionResult> Edit([Bind(Include = "VoteID,UserID,ProblemID,upVote")] ProblemVote problemVote) { if (ModelState.IsValid) { db.Entry(problemVote).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.ProblemID = new SelectList(db.Problems, "ProblemID", "Title", problemVote.ProblemID); return(View(problemVote)); }
public async Task <ActionResult> Edit([Bind(Include = "BusinessCategoryID,Title,Description,CompanyID")] BusinessCategory businessCategory) { if (ModelState.IsValid) { db.Entry(businessCategory).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.CompanyID = new SelectList(db.Companies, "CompanyID", "CompanyName", businessCategory.CompanyID); return(View(businessCategory)); }
public async Task <BaseResponse> UpdateVoting(ModelVotingView model) { BaseResponse response = new BaseResponse(); using (var dbcxtransaction = await _context.Database.BeginTransactionAsync()) { try { var voting = await _context.MasterVotingProcess.FindAsync(model.VotingProcessId); voting.VotingProcessName = model.VotingProcessName; voting.Description = model.Description; voting.CreatedDate = model.CreatedDate; voting.DueDate = model.DueDate; voting.VotingCategoryId = model.VotingCategoryId; voting.ModifiedDate = DateTime.Now; voting.ModifiedBy = "Admin"; _context.Entry(voting).State = EntityState.Modified; await _context.SaveChangesAsync(); dbcxtransaction.Commit(); response.Code = (int)HttpStatusCode.OK; response.Status = HttpStatusCode.OK.ToString(); response.Message = "Update data success."; } catch (Exception ex) { response.Message = ex.ToString(); response.Code = (int)HttpStatusCode.InternalServerError; response.Status = HttpStatusCode.InternalServerError.ToString(); dbcxtransaction.Rollback(); } } return(response); }