/// <summary> /// Create a new Budgets_UsersToBaskets object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="companyId">Initial value of the CompanyId property.</param> /// <param name="creationDate">Initial value of the CreationDate property.</param> /// <param name="userId">Initial value of the UserId property.</param> /// <param name="basketId">Initial value of the BasketId property.</param> public static Budgets_UsersToBaskets CreateBudgets_UsersToBaskets(global::System.Int32 id, global::System.Int32 companyId, global::System.DateTime creationDate, global::System.Int32 userId, global::System.Int32 basketId) { Budgets_UsersToBaskets budgets_UsersToBaskets = new Budgets_UsersToBaskets(); budgets_UsersToBaskets.Id = id; budgets_UsersToBaskets.CompanyId = companyId; budgets_UsersToBaskets.CreationDate = creationDate; budgets_UsersToBaskets.UserId = userId; budgets_UsersToBaskets.BasketId = basketId; return budgets_UsersToBaskets; }
/// <summary> /// Deprecated Method for adding a new object to the Budgets_UsersToBaskets EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToBudgets_UsersToBaskets(Budgets_UsersToBaskets budgets_UsersToBaskets) { base.AddObject("Budgets_UsersToBaskets", budgets_UsersToBaskets); }
public ActionResult EditBaskets(UserPermissionsModel model) { if (ModelState.IsValid) { if (Authorized(RoleType.SystemManager)) { User userFromDB; List<Budgets_UsersToBaskets> existingPermissions; bool noErrors = true; using (UsersRepository usersRep = new UsersRepository(CurrentUser.CompanyId)) using (UsersToBasketsRepository userPermissionsRep = new UsersToBasketsRepository()) { userFromDB = usersRep.GetEntity(model.UserId); if (userFromDB != null) { if (userFromDB.CompanyId == CurrentUser.CompanyId) { existingPermissions = userPermissionsRep.GetList().Where(x => x.UserId == userFromDB.Id).ToList(); if (existingPermissions != null) { if (model.UserPermissions == null) return RedirectToAction("Index"); foreach (var permission in model.UserPermissions) { if (permission.IsActive) { if (!existingPermissions.Any(x => x.BasketId == permission.Permission.Id)) { Budgets_UsersToBaskets newPermission = new Budgets_UsersToBaskets() { UserId = userFromDB.Id, BasketId = permission.Permission.Id, CompanyId = CurrentUser.CompanyId }; if (!userPermissionsRep.Create(newPermission)) noErrors = false; } } else { Budgets_UsersToBaskets existingPermission = existingPermissions.SingleOrDefault(x => x.BasketId == permission.Permission.Id); if (existingPermission != null) { if (!userPermissionsRep.Delete(existingPermission.Id)) noErrors = false; } } } if (noErrors) return RedirectToAction("Index"); else return Error(Loc.Dic.error_user_edit_permissions_error); } else { return Error(Loc.Dic.error_database_error); } } else { return Error(Loc.Dic.error_no_permission); } } else { return Error(Loc.Dic.error_database_error); } } } else { return Error(Loc.Dic.error_no_permission); } } else { return Error(ModelState); } }