public async Task <TEntity> AddAsync(TEntity entity) { var result = _votingContext.Set <TEntity>().Add(entity).Entity; await _votingContext.SaveChangesAsync(); return(result); }
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 <string> UpdateUserAsync(User user) { try { if (user == null) { return("User object is null."); } var entity = _db.User.FirstOrDefault(i => i.Id == user.Id); if (entity != null) { entity.Name = user.Name; await _db.SaveChangesAsync(); return("User changed successfully!"); } else { return("Nonexistent User."); } } catch (Exception ex) { return(ex.Message); } }
public async Task <IActionResult> Create([Bind("PersonID,Name,Count")] Person person) { if (ModelState.IsValid) { _context.Add(person); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(person)); }
public async Task <ActionResult> Create([Bind(Include = "CategoryID,Title,Description")] Category category) { if (ModelState.IsValid) { db.Categories.Add(category); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(category)); }
public async Task <ActionResult> Create([Bind(Include = "VoteID,UserID,ProblemID,upVote")] ProblemVote problemVote) { if (ModelState.IsValid) { db.ProblemVotes.Add(problemVote); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.ProblemID = new SelectList(db.Problems, "ProblemID", "Title", problemVote.ProblemID); return(View(problemVote)); }
public async Task <ActionResult> Create([Bind(Include = "CommentID,UserID,UserComment,CreationDate,BusinessChannelID")] IdeaComment ideaComment) { if (ModelState.IsValid) { db.IdeaComments.Add(ideaComment); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.BusinessChannelID = new SelectList(db.BusinessChannels, "BusinessChannelID", "Title", ideaComment.BusinessChannelID); return(View(ideaComment)); }
public async Task <ActionResult> Create([Bind(Include = "HoursOfOperationID,DayOfWeek,TimeOpen,LocationID")] HoursOfOperation hoursOfOperation) { if (ModelState.IsValid) { db.HoursOfOperations.Add(hoursOfOperation); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.LocationID = new SelectList(db.Locations, "LocationID", "StreetAddress1", hoursOfOperation.LocationID); return(View(hoursOfOperation)); }
public async Task <ActionResult> Create([Bind(Include = "BusinessChannelID,CategoryID,Title,Description,CreationDate")] BusinessChannel businessChannel) { if (ModelState.IsValid) { db.BusinessChannels.Add(businessChannel); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.CategoryID = new SelectList(db.Categories, "CategoryID", "Title", businessChannel.CategoryID); return(View(businessChannel)); }
public async Task <ActionResult> Create([Bind(Include = "BusinessCategoryID,Title,Description,CompanyID")] BusinessCategory businessCategory) { if (ModelState.IsValid) { db.BusinessCategories.Add(businessCategory); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.CompanyID = new SelectList(db.Companies, "CompanyID", "CompanyName", businessCategory.CompanyID); return(View(businessCategory)); }
public async Task <ActionResult> Create([Bind(Include = "CompanyID,CompanyName,Description")] Company company) { if (ModelState.IsValid) { company.CreationDate = DateTime.Now; db.Companies.Add(company); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(company)); }
public async Task <ActionResult> Create([Bind(Include = "VoteID,UserID,upVote,CreationDate,SolutionID")] IdeaVote ideaVote) { if (ModelState.IsValid) { db.IdeaVotes.Add(ideaVote); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.SolutionID = new SelectList(db.Ideas, "IdeaID", "UserID", ideaVote.SolutionID); return(View(ideaVote)); }
public async Task <ActionResult> Create([Bind(Include = "LocationID,StreetAddress1,StreetAddress2,ZipCode,City,State,Phone,website,CompanyID")] Location location) { if (ModelState.IsValid) { db.Locations.Add(location); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.CompanyID = new SelectList(db.Companies, "CompanyID", "CompanyName", location.CompanyID); return(View(location)); }
public async Task <ActionResult> Create([Bind(Include = "SolutionID,UserID,ProblemID,ChannelID,Title,Description")] Solution solution) { if (ModelState.IsValid) { db.Solutions.Add(solution); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.ChannelID = new SelectList(db.Channels, "ChannelID", "Title", solution.ChannelID); ViewBag.ProblemID = new SelectList(db.Problems, "ProblemID", "Title", solution.ProblemID); return(View(solution)); }
public async Task <ActionResult> Create([Bind(Include = "ProblemID,UserID,ChannelID,Title,Description")] Problem problem) { if (ModelState.IsValid) { problem.CreationDate = DateTime.Today; db.Problems.Add(problem); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.ChannelID = new SelectList(db.Channels, "ChannelID", "Title", problem.ChannelID); return(View(problem)); }
public async Task <int> Handle(AdaugaNotaCommand message) { try { if (message.IdIntrebare.HasValue && message.IdIntrebare.Value > 0) { var existaIntrebare = await _context.Questions.AnyAsync(i => i.Id == message.IdIntrebare.Value); if (!existaIntrebare) { throw new ArgumentException("Intrebarea nu exista"); } } var nota = _mapper.Map <Note>(message); _context.Add(nota); return(await _context.SaveChangesAsync()); } catch (Exception ex) { _logger.LogError(new EventId(), ex.Message); } return(-1); }
public async Task <int> Handle(ActualizeazaSectieCommand message) { try { var formular = await _context.RaspunsFormular .FirstOrDefaultAsync(a => a.IdObservator == message.IdObservator && a.IdSectieDeVotare == message.IdSectieDeVotare); if (formular == null) { throw new ArgumentException("RaspunsFormular nu exista"); } _mapper.Map(message, formular); _context.Update(formular); return(await _context.SaveChangesAsync()); } catch (Exception ex) { _logger.LogError(new EventId(), ex.Message); } return(-1); }
protected override async Task <int> HandleCore(ActualizeazaSectieCommand message) { try { var formular = await _context.PollingStationInfos .FirstOrDefaultAsync(a => a.IdObserver == message.IdObservator && a.IdPollingStation == message.IdSectieDeVotare); if (formular == null) { throw new ArgumentException("PollingStationInfo nu exista"); } _mapper.Map(message, formular); _context.Update(formular); return(await _context.SaveChangesAsync()); } catch (Exception ex) { _logger.LogError(new EventId(), ex.Message); } return(-1); }
public async Task <int> Handle(CompleteazaRaspunsCommand message) { try { //flat answers var lastModified = DateTime.UtcNow; var raspunsuriNoi = message.Raspunsuri.Select(a => new { flat = a.Optiuni.Select(o => new Raspuns { IdObservator = message.IdObservator, IdSectieDeVotare = a.IdSectie, IdRaspunsDisponibil = o.IdOptiune, Value = o.Value, CodJudet = a.CodJudet, NumarSectie = a.NumarSectie, DataUltimeiModificari = lastModified }) }).SelectMany(a => a.flat) .Distinct() .ToList(); // stergerea este pe fiecare sectie var sectii = message.Raspunsuri.Select(a => a.IdSectie).Distinct().ToList(); using (var tran = await _context.Database.BeginTransactionAsync()) { foreach (var sectie in sectii) { var intrebari = message.Raspunsuri.Select(a => a.IdIntrebare).Distinct().ToList(); // delete existing answers for posted questions on this 'sectie' _context.Raspuns .Include(a => a.IdRaspunsDisponibilNavigation) .Where( a => a.IdObservator == message.IdObservator && a.IdSectieDeVotare == sectie) .WhereRaspunsContains(intrebari) .Delete(); } _context.Raspuns.AddRange(raspunsuriNoi); var result = await _context.SaveChangesAsync(); tran.Commit(); return(result); } } catch (Exception ex) { _logger.LogError(typeof(CompleteazaRaspunsCommand).GetHashCode(), ex, ex.Message); } return(await Task.FromResult(-1)); }
public async Task <BaseResponse> InsertUser(ModelUserView model) { BaseResponse response = new BaseResponse(); using (var dbcxtransaction = await _context.Database.BeginTransactionAsync()) { try { if (_context.MasterUser.Where(n => n.Email == model.Email || n.UserName == model.UserName).Count() == 0) { MasterUser newUser = new MasterUser { UserName = model.UserName, FirstName = model.FirstName, LastName = model.LastName, Email = model.Email, Password = model.Password, RoleId = model.RoleId, Gender = model.Gender, Age = model.Age, CreatedDate = DateTime.Now, CreatedBy = model.UserName, ModifiedDate = DateTime.Now, ModifiedBy = model.UserName, IsDelete = false }; await _context.MasterUser.AddAsync(newUser); await _context.SaveChangesAsync(); dbcxtransaction.Commit(); response = ResponseConstant.SAVE_SUCCESS; } else { response.Code = (int)HttpStatusCode.BadRequest; response.Status = HttpStatusCode.BadRequest.ToString(); response.Message = "Email already exist."; dbcxtransaction.Rollback(); } } catch (Exception ex) { response.Message = ex.ToString(); response.Code = (int)HttpStatusCode.InternalServerError; response.Status = HttpStatusCode.InternalServerError.ToString(); dbcxtransaction.Rollback(); } } return(response); }
public async Task <BaseResponse> InsertVoting(Models.Models.View.ModelVotingView model) { BaseResponse response = new BaseResponse(); using (var dbcxtransaction = await _context.Database.BeginTransactionAsync()) { try { MasterVotingProcess newVoting = new MasterVotingProcess { VotingProcessName = model.VotingProcessName, Description = model.Description, CreatedDate = model.CreatedDate, DueDate = model.DueDate, VotingCategoryId = model.VotingCategoryId, SupportersCount = 0, CreatedBy = "Admin", ModifiedDate = DateTime.Now, ModifiedBy = "Admin", IsDelete = false }; await _context.MasterVotingProcess.AddAsync(newVoting); await _context.SaveChangesAsync(); dbcxtransaction.Commit(); response = ResponseConstant.SAVE_SUCCESS; } catch (Exception ex) { response.Message = ex.ToString(); response.Code = (int)HttpStatusCode.InternalServerError; response.Status = HttpStatusCode.InternalServerError.ToString(); dbcxtransaction.Rollback(); } } return(response); }
public virtual async Task <IActionResult> Answer(int id, int answerId) { var question = await _db.Questions.Include(q => q.PossibleAnswers).FirstAsync(q => q.Id == id); var answer = question.PossibleAnswers.First(a => a.Id == answerId); _db.Answers.Add(new Core.Answer() { PossibleAnswer = answer, Question = question }); await _db.SaveChangesAsync(); return(RedirectToAction("Vote", new { id = question.Id + 1 })); }
protected override async Task <int> HandleCore(RegisterDeviceId request) { try { var observator = await _context.Observers.SingleAsync(a => a.Id == request.ObserverId); observator.MobileDeviceId = request.MobileDeviceId; observator.DeviceRegisterDate = DateTime.UtcNow; return(await _context.SaveChangesAsync()); } catch (Exception ex) { _logger.LogError(new EventId(), ex, ex.Message); throw ex; } }
public async Task <int> Handle(InregistreazaDispozitivCommand message) { try { var observator = await _context.Observator.SingleAsync(a => a.IdObservator == message.IdObservator); observator.IdDispozitivMobil = message.IdDispozitivMobil; observator.DataInregistrariiDispozitivului = DateTime.UtcNow; return(await _context.SaveChangesAsync()); } catch (Exception ex) { _logger.LogError(new EventId(), ex, ex.Message); } return(-1); }
protected override async Task <int> HandleCore(InregistreazaSectieCommand message) { try { //TODO[DH] this can be moved to a previous step, before the command is executed int idSectie = await _context.PollingStations .Where(a => a.Number == message.NumarSectie && a.County.Code == message.CodJudet).Select(a => a.Id) .FirstOrDefaultAsync(); if (idSectie == 0) { throw new ArgumentException("Sectia nu exista"); } var formular = await _context.PollingStationInfos .FirstOrDefaultAsync(a => a.IdObserver == message.IdObservator && a.IdPollingStation == idSectie); if (formular == null) { formular = _mapper.Map <PollingStationInfo>(message); formular.IdPollingStation = idSectie; _context.Add(formular); } else { _mapper.Map(message, formular); } return(await _context.SaveChangesAsync()); } catch (Exception ex) { _logger.LogError(new EventId(), ex.Message); } return(-1); }
public async Task <int> Handle(InregistreazaSectieCommand message) { try { //TODO[DH] this can be moved to a previous step, before the command is executed int idSectie = await _context.SectieDeVotare .Where(a => a.NumarSectie == message.NumarSectie && a.IdJudetNavigation.CodJudet == message.CodJudet).Select(a => a.IdSectieDeVotarre) .FirstOrDefaultAsync(); if (idSectie == 0) { throw new ArgumentException("Sectia nu exista"); } var formular = await _context.RaspunsFormular .FirstOrDefaultAsync(a => a.IdObservator == message.IdObservator && a.IdSectieDeVotare == idSectie); if (formular == null) { formular = _mapper.Map <RaspunsFormular>(message); formular.IdSectieDeVotare = idSectie; _context.Add(formular); } else { _mapper.Map(message, formular); } return(await _context.SaveChangesAsync()); } catch (Exception ex) { _logger.LogError(new EventId(), ex.Message); } return(-1); }
public async Task Post([FromBody] Poll poll) { _votingContext.Add(poll); await _votingContext.SaveChangesAsync(); }