public async Task <IActionResult> DeleteNews(ShowCompanyViewModel model) { _db.News.Remove(_db.News.FirstOrDefault(item => item.id == model.deleteNewsID)); await _db.SaveChangesAsync(); return(RedirectToAction(model.Id + "", "Company")); }
public async Task <IActionResult> AddNews(ShowCompanyViewModel model) { Company company = _db.Companies.FirstOrDefault(item => item.id == model.Id); if (company != null) { _db.News.Add(new News { company = company, name = model.addNews.Name, description = model.addNews.Description, image = model.addNews.Image }); await _db.SaveChangesAsync(); } return(RedirectToAction(model.Id + "", "Company")); }
public async Task <IActionResult> Pay(ShowCompanyViewModel model) { Bonus bonus = _db.Bonus.FirstOrDefault(item => item.id == model.payID); if (bonus != null) { Company company = _db.Companies.FirstOrDefault(item => item.id == bonus.companyID); if (company != null) { User user = await _userManager.GetUserAsync(User); company.colectedSum = (int.Parse(company.colectedSum) + int.Parse(bonus.sum)) + ""; _db.Companies.Update(company); _db.BonusesToUsers.Add(new BonusesToUser { bonus = bonus, user = user }); await _db.SaveChangesAsync(); } } return(RedirectToAction(model.Id + "", "Company")); }
public async Task <IActionResult> SetMark(ShowCompanyViewModel model) { User user = await _userManager.GetUserAsync(User); Company company = _db.Companies.FirstOrDefault(item => item.id == model.Id); Mark mark = _db.Marks.FirstOrDefault(item => item.company == company && item.user == user); for (int i = 4; i >= 0; i--) { if (model.mark[i] == true) { if (mark == null) { _db.Marks.Add(new Mark { company = company, user = user, value = i }); await _db.SaveChangesAsync(); return(RedirectToAction(model.Id + "", "Company")); } else { mark.value = i; _db.Marks.Update(mark); await _db.SaveChangesAsync(); return(RedirectToAction(model.Id + "", "Company")); } } } if (mark != null) { _db.Marks.Remove(mark); await _db.SaveChangesAsync(); } return(RedirectToAction(model.Id + "", "Company")); }