public ActionResult Edit(Limit limit) { if (ModelState.IsValid) { db.Entry(limit).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(limit); }
public ActionResult AddLimit(Limit limit) { if (ModelState.IsValid) { db.Limit.Add(limit); db.SaveChanges(); return RedirectToAction("Index"); } return View(limit); }
public dynamic GetUserData() { var b = HttpContext.Current.User as SocialPackage.Infrastructure.Entities.User; var user = db.Users.Find(b.id); var userLimitsInCurrYear = db.Bids.Where(el => el.BidUser.id == user.id && el.Date.Year == DateTime.Now.Year); var CurrentLimits = new Limit() { Proezd = user.Limit.Proezd > 0 ? user.Limit.Proezd - userLimitsInCurrYear.Where(el => el.category.id == 1 && el.Status != BidStatus.Declined).ToArray().Sum(el => el.Summ) : user.Limit.Proezd, CultureEvents = user.Limit.CultureEvents > 0 ? user.Limit.CultureEvents - userLimitsInCurrYear.Where(el => el.category.id == 3 && el.Status != BidStatus.Declined).ToArray().Sum(el => el.Summ) : user.Limit.CultureEvents, Fitnes = user.Limit.Fitnes > 0 ? user.Limit.Fitnes - userLimitsInCurrYear.Where(el => el.category.id == 2 && el.Status != BidStatus.Declined).ToArray().Sum(el => el.Summ) : user.Limit.Fitnes }; return new { id = user.id, FullName = user.FullName, GeneralLimit = user.Limit, Limit = CurrentLimits, Roles = user.Roles.Select(el => el.RoleName).ToArray() }; }
public ActionResult Index(SettingsViewModel model) { if (!ModelState.IsValid) { return View(model); } //context.Categories.RemoveRange(context.Categories); //context.Limit.RemoveRange(context.Limit); //var categories = new List<Category> { // new Category { Color = "#755bee", Name="Проездные"}, // new Category { Color = "#3ec172", Name="Фитнес"}, // new Category { Color = "#e73f72", Name="Соц. Мероприятия"} //}; Limit firstUserLimit; if (dbContext.Limit.Count() == 0) { firstUserLimit = new Limit { CultureEvents = -1, Fitnes = -1, Proezd = -1, Name = "Пустой лимит" }; dbContext.Limit.Add(firstUserLimit); } else firstUserLimit = dbContext.Limit.First(); if (dbContext.Categories.Count() == 0) { var categories = new List<Category> { new Category { Color = "#755bee", Name="Проездные"}, new Category { Color = "#3ec172", Name="Фитнес"}, new Category { Color = "#e73f72", Name="Соц. Мероприятия"} }; dbContext.Categories.AddRange(categories); } List<UserRole> roles; if (dbContext.UserRole.Count() == 0) { roles = new List<UserRole> { new UserRole { RoleName = "Пользователь"}, new UserRole { RoleName = "Администратор"}, new UserRole { RoleName = "Бухгалтер"}, new UserRole { RoleName = "Секретарь"} }; dbContext.UserRole.AddRange(roles); } else roles = dbContext.UserRole.ToList(); var user = new User { FullName = model.User.FullName, Email = model.User.Email, Login = model.User.Login, Roles = roles.Where(c => c.RoleName == "Администратор").ToList(), Limit = firstUserLimit }; dbContext.Users.Add(user); dbContext.SaveChanges(); Session.Abandon(); return RedirectToAction("Index", "Users"); }