public async Task <IActionResult> AddToDaily(int vicId) { var vic = this.vicoveRepository.All() .FirstOrDefault(x => x.Id == vicId); var checkIfAlreadyHas = this.vicNaDenqRepo.All().Any(x => x.Day == DateTime.UtcNow.Date.AddDays(1)); // da sloja da invokeva js v gorniq controller ili da go sloja v signalR Huba if (checkIfAlreadyHas) { return(this.Content("Вече е избран виц на деня")); } else { var dailyVic = new VicNaDenq() { Content = vic.Content, Day = DateTime.UtcNow.Date.AddDays(1), VicType = vic.VicType, Points = vic.Points, Creator = vic.Creator, CreatedOn = vic.CreatedOn, }; await this.vicNaDenqRepo.AddAsync(dailyVic); await this.vicNaDenqRepo.SaveChangesAsync(); return(this.RedirectToAction("Index")); } }
public async Task <IActionResult> CreateAsync(VicNaDenqViewModel daily) { if (!this.ModelState.IsValid) { return(this.View(daily)); } var vic = new VicNaDenq() { Content = daily.Content, Day = DateTime.Today, VicType = daily.VicType, }; await this.dailyRepo.AddAsync(vic); await this.dailyRepo.SaveChangesAsync(); return(this.RedirectToPage("/Home/Index")); }