public async Task <IActionResult> ProductAvalibalityChange(int productId) { LocalItem localItem = await db.LocalItems.SingleOrDefaultAsync(p => p.BasicItem.Id == productId); if (localItem == null) { Item item = await db.Items.SingleOrDefaultAsync(p => p.Id == productId); if (item != null) { localItem = new LocalItem { BasicItem = item, IsAvalible = true }; db.LocalItems.Add(localItem); } } else { localItem.IsAvalible = !localItem.IsAvalible; } await db.SaveChangesAsync(); await logger.AddToLogAsync($"Changed avalibality on product ID:{productId} to {localItem.IsAvalible}"); return(RedirectToAction("Products")); }
public async Task <IActionResult> DeleteProductFromCategory(int productId, int categoryId) { ItemToCategory itemToCategory = await db.ItemsToCategories.SingleOrDefaultAsync(p => (p.ItemId == productId) && (p.CategoryId == categoryId)); if (itemToCategory != null) { db.ItemsToCategories.Remove(itemToCategory); await db.SaveChangesAsync(); await logger.AddToLogAsync($"Product ID:{itemToCategory.ItemId} deleted from category ID:{itemToCategory.CategoryId}"); } return(RedirectToRoute("AdminSelectToAddToCategory", new { categoryId })); }
public async Task <IActionResult> Delete(int accountId) { AdministratorUser user = await db.AdministratorUsers.SingleOrDefaultAsync(p => p.Id == accountId); if (user.Tier >= maxTier) { int maxTierUsers = await db.AdministratorUsers.Where(p => p.Tier >= maxTier).CountAsync(); if (maxTierUsers <= minimumMaxTierUsers) { return(RedirectToRoute("ErrorMessage", new { Message = $"Total number of users with Tier >= {maxTier} must be higher or equal to {minimumMaxTierUsers} after delete.", RedirectRoute = "AdminAccounts" })); } } db.AdministratorUsers.Remove(user); await db.SaveChangesAsync(); await logger.AddToLogAsync($"Deleted account ID:{accountId}"); return(RedirectToAction("Accounts")); }
/// <summary> /// Add record to log /// </summary> /// <param name="message">Record message</param> public async Task AddToLogAsync(string message) { if (db == null) { throw new EntryPointNotFoundException("Relation to context isn't setup"); } db.Log.Add(new LogRecord { UserId = userId, Record = message, AdministratorUser = adminUser }); await db.SaveChangesAsync(); }