public SupplyResponse Post(string id, [FromBody] IdRequest idRequest) { if (idRequest == null || string.IsNullOrWhiteSpace(idRequest.Id)) { return(SupplyResponse.RequiredFieldEmpty()); } var vItem = _dbContext.VirtualItem.SingleOrDefault(p => p.VirtualItemId == idRequest.Id); var item = _dbContext.Item.SingleOrDefault(p => p.SupplierItemId == id); if (item == null) { return(SupplyResponse.NotFound("item", id)); } if (vItem == null) { return(SupplyResponse.NotFound("virtual item", idRequest.Id)); } if (_dbContext.VirtualIdMap.SingleOrDefault(p => p.ItemId == item.Id && p.VirtualItemId == vItem.Id) != null) { return(SupplyResponse.DuplicateEntry("virtual map", $"{id}<->{idRequest.Id}")); } _dbContext.VirtualIdMap.Add(new VirtualIdMap { ItemId = item.Id, VirtualItemId = vItem.Id }); _dbContext.SaveChanges(); return(SupplyResponse.Ok()); }
public SupplyResponse Get(int id) { var category = _dbContext.Category.Include(a => a.CategoryItems).ThenInclude(a => a.VirtualItem).SingleOrDefault(p => p.CategoryId == id); if (category == null) { return(SupplyResponse.NotFound("category", id + "")); } var categoryItemResponse = new CategoryItemResponse { Category = category, VirtualItemId = new List <string>() }; if (category.CategoryItems != null) { foreach (var categoryItem in category.CategoryItems) { categoryItemResponse.VirtualItemId.Add(categoryItem.VirtualItem.VirtualItemId); } category.CategoryItems = null; } return(SupplyResponse.Ok(categoryItemResponse)); }
public SupplyResponse Get(int id) { var stock = _dbContext.Stock.Include(a => a.StockItem).ThenInclude(a => a.VirtualItem) .SingleOrDefault(p => p.StockId == id); return(SupplyResponse.Ok(stock)); }
public SupplyResponse CreateToken([FromBody] LoginRequest login) { var response = SupplyResponse.Fail("Unauthorize", "Your are not the user in the system."); var user = Authenticate(login); if (user != null) { var expiry = DateTime.Now.AddDays(1); var tokenString = BuildToken(expiry, user); var restaurantManager = user.RestaurantManager; dynamic workplace = null; if (restaurantManager != null) { workplace = new { restaurantId = restaurantManager.RestaurantId, stockId = restaurantManager.Restaurant.StockId }; } response = SupplyResponse.Ok(new { token = tokenString, userType = user.UserType, expiry, user, workplace }); } return(response); }
public SupplyResponse Get() { var currentUser = HttpContext.User; var dbUser = _dbContext.User.Include(p => p.RestaurantManager).ThenInclude(p => p.Restaurant) .SingleOrDefault(p => currentUser.FindFirst(ClaimTypes.Name).Value.Equals(p.UserName)); if (dbUser == null) { return(SupplyResponse.Fail("Unauthorize", "Your are not the user in the system.")); } var restaurantManager = dbUser.RestaurantManager; if (restaurantManager == null) { return(SupplyResponse.Fail("Unauthorize", "Your are not the restaurant manager.")); } var restaurantId = restaurantManager.Restaurant.RestaurantId; var requests = _dbContext.Request.Include(p => p.User).Include(p => p.RequestItem) .ThenInclude(p => p.VirtualItem).Include(p => p.RequestMap) .Where(p => p.RestaurantId == restaurantId) .Select(p => p); foreach (var request in requests) { foreach (var requestItem in request.RequestItem) { requestItem.VirtualItemName = requestItem.VirtualItem.VirtualItemName; requestItem.RequestVirtualItemId = requestItem.VirtualItem.VirtualItemId; } } return(SupplyResponse.Ok(requests)); }
public SupplyResponse Get() { var currentUser = HttpContext.User; var dbUser = _dbContext.User.Include(p => p.RestaurantManager).ThenInclude(p => p.Restaurant) .SingleOrDefault(p => currentUser.FindFirst(ClaimTypes.Name).Value.Equals(p.UserName)); if (dbUser == null) { return(SupplyResponse.Fail("Unauthorize", "Your are not the user in the system.")); } if (dbUser.UserType == UserType.RestaurantManager) { var restaurantManager = dbUser.RestaurantManager; if (restaurantManager == null) { return(SupplyResponse.Fail("Unauthorize", "Your are not the restaurant manager of any restaurant.")); } return(SupplyResponse.Ok(new { stock = restaurantManager.Restaurant.StockId })); } var id = _dbContext.Stock.FirstOrDefault(p => p.StockType == StockType.WarehouseStock).StockId; return(SupplyResponse.Ok(new { stock = id })); }
public SupplyResponse Get(int id) { var restaurant = _dbContext.Restaurant.Include(p => p.RestaurantManager) .SingleOrDefault(p => p.RestaurantId == id); return(SupplyResponse.Ok(restaurant)); }
public SupplyResponse Get() { var categories = _dbContext.Category.Include(a => a.CategoryItems).ThenInclude(a => a.VirtualItem).Select(p => p); var categoryItemResponses = new List <CategoryItemResponse>(); foreach (var category in categories) { var categoryItemResponse = new CategoryItemResponse { Category = category, VirtualItemId = new List <string>() }; if (category.CategoryItems != null) { foreach (var categoryItem in category.CategoryItems) { categoryItemResponse.VirtualItemId.Add(categoryItem.VirtualItem.VirtualItemId); } category.CategoryItems = null; } categoryItemResponses.Add(categoryItemResponse); } return(SupplyResponse.Ok(categoryItemResponses)); }
public SupplyResponse Delete(int id) { var entity = _dbContext.Restaurant.SingleOrDefault(p => p.RestaurantId == id); if (entity == null) return SupplyResponse.NotFound("restaurant", id + ""); _dbContext.Remove(entity); _dbContext.SaveChanges(); return SupplyResponse.Ok(); }
public SupplyResponse Delete(int id) { var datas = _dbContext.DataCache.SingleOrDefault(p => p.DataCacheId == id); _dbContext.DataCache.Remove(datas); _dbContext.SaveChanges(); return(SupplyResponse.Ok()); }
public SupplyResponse Get() { var orders = _dbContext.DeliveryNote.Include(p => p.Request) .ThenInclude(p => p.RequestItem).ThenInclude(p => p.VirtualItem).Include(p => p.Request) .ThenInclude(p => p.Restaurant).Select(p => p); return(SupplyResponse.Ok(orders)); }
public SupplyResponse Get(int id) { var order = _dbContext.DeliveryNote.Include(p => p.Request) .ThenInclude(p => p.RequestItem).ThenInclude(p => p.VirtualItem).Include(p => p.Request) .ThenInclude(p => p.Restaurant) .SingleOrDefault(p => p.RequestId == id); return(order == null?SupplyResponse.NotFound("Delivery Note", id + "") : SupplyResponse.Ok(order)); }
public SupplyResponse Get() { var orders = _dbContext.BlanketRelease.Include(p => p.Agreement).ThenInclude(p => p.Supplier).Include(p => p.Request) .ThenInclude(p => p.RequestItem).Include(p => p.BlanketReleaseLine).ThenInclude(p => p.Item).Include(p => p.Request) .ThenInclude(p => p.Restaurant) .Select(p => p); return(SupplyResponse.Ok(orders)); }
public SupplyResponse Get() { var orders = _dbContext.ScheduleRelease.Include(p => p.Agreement) .ThenInclude(p => p.PlannedPurchaseAgreementDetails).Include(p => p.Agreement) .ThenInclude(p => p.Supplier).Include(p => p.Agreement) .ThenInclude(p => p.PlannedPurchaseAgreementLines).ThenInclude(p => p.Item).Select(p => p); return(SupplyResponse.Ok(orders)); }
public SupplyResponse Get() { var agreements = _dbContext.Agreement.Select(p => p).Include(p => p.BlanketPurchaseAgreementDetails) .Include(p => p.BlanketPurchaseAgreementLines).ThenInclude(p => p.Item) .Include(p => p.ContractPurchaseAgreementDetails).Include(p => p.ContractPurchaseAgreementLines) .ThenInclude(p => p.Item).Include(p => p.PlannedPurchaseAgreementDetails) .Include(p => p.PlannedPurchaseAgreementLines).ThenInclude(p => p.Item); return(SupplyResponse.Ok(agreements)); }
public SupplyResponse Get(int id) { var supplier = _dbContext.Supplier.SingleOrDefault(p => p.SupplierId == id); if (supplier == null) { return(SupplyResponse.NotFound("supplier", id + "")); } return(SupplyResponse.Ok(supplier)); }
public SupplyResponse Get(int id) { var item = _dbContext.Category.SingleOrDefault(p => p.CategoryId == id); if (item == null) { return(SupplyResponse.NotFound("categorty", id + "")); } return(SupplyResponse.Ok(item)); }
public SupplyResponse Get() { var orders = _dbContext.StandardPurchaseOrder.Include(p => p.Agreement).ThenInclude(p => p.Supplier) .Include(p => p.Request) .ThenInclude(p => p.RequestItem).Include(p => p.StandardPurchaseOrderLine).ThenInclude(p => p.Item) .Include(p => p.Request) .ThenInclude(p => p.Restaurant).Select(p => p); return(SupplyResponse.Ok(orders)); }
public SupplyResponse Get(string id) { var item = _dbContext.Item.SingleOrDefault(p => p.SupplierItemId.Equals(id)); if (item == null) { return(SupplyResponse.NotFound("item", id)); } return(SupplyResponse.Ok(item)); }
public SupplyResponse Get(int id) { var agreement = _dbContext.Agreement.Include(p => p.BlanketPurchaseAgreementDetails) .Include(p => p.BlanketPurchaseAgreementLines).ThenInclude(p => p.Item) .Include(p => p.ContractPurchaseAgreementDetails).Include(p => p.ContractPurchaseAgreementLines) .ThenInclude(p => p.Item).Include(p => p.PlannedPurchaseAgreementDetails) .Include(p => p.PlannedPurchaseAgreementLines).ThenInclude(p => p.Item) .SingleOrDefault(p => p.AgreementId == id); return(SupplyResponse.Ok(agreement)); }
public SupplyResponse Get(int id) { var user = _dbContext.User.SingleOrDefault(p => p.UserId == id); if (user == null) { return(SupplyResponse.NotFound("user", id + "")); } user.Password = null; return(SupplyResponse.Ok(user)); }
public SupplyResponse Get() { var datas = _dbContext.DataCache.Where(p => p.CacheType == "Announcement") .Select(p => new { CreateTime = p.CacheTime, Id = p.DataCacheId, Data = JsonConvert.DeserializeObject(p.Content) }); return(SupplyResponse.Ok(datas)); }
public SupplyResponse Delete(int id) { var user = _dbContext.User.SingleOrDefault(p => p.UserId == id); if (user == null) { return(SupplyResponse.NotFound("user", id + "")); } _dbContext.Remove(user); _dbContext.SaveChanges(); return(SupplyResponse.Ok()); }
public SupplyResponse Delete(int id) { var entity = _dbContext.Category.SingleOrDefault(p => p.CategoryId == id); if (entity == null) { return(SupplyResponse.NotFound("category", id + "")); } _dbContext.Remove(entity); _dbContext.SaveChanges(); return(SupplyResponse.Ok()); }
public SupplyResponse Delete(string id, [FromBody] IdRequest idRequest) { var entity = _dbContext.VirtualIdMap.SingleOrDefault(p => p.VirtualItem.VirtualItemId == idRequest.Id && p.Item.SupplierItemId == id); if (entity == null) { return(SupplyResponse.NotFound("virtual map", $"{id}<->{idRequest.Id}")); } _dbContext.Remove(entity); _dbContext.SaveChanges(); return(SupplyResponse.Ok()); }
public SupplyResponse RemoveFromStock(int id, [FromBody] IdRequest idRequest) { var stockItem = _dbContext.StockItem.SingleOrDefault(p => p.StockId == id && p.VirtualItem.VirtualItemId == idRequest.Id); if (stockItem == null) { return(SupplyResponse.NotFound("stock item", $"\"{idRequest.Id} in {id}\"")); } _dbContext.StockItem.Remove(stockItem); _dbContext.SaveChanges(); return(SupplyResponse.Ok()); }
public SupplyResponse Get() { /* * HOW TO FIND USERNAME AND ROLE OF USER * var currentUser = HttpContext.User; * Console.WriteLine(currentUser.FindFirst(ClaimTypes.Name).Value); * Console.WriteLine(currentUser.FindFirst(ClaimTypes.Role).Value); */ var users = _dbContext.User.Select(p => p); foreach (var user in users) { user.Password = null; } return(SupplyResponse.Ok(users)); }
public SupplyResponse AddRestaurantType([FromBody] RestaurantType nameRequest) { if (string.IsNullOrWhiteSpace(nameRequest.RestaurantTypeName)) { return(SupplyResponse.RequiredFieldEmpty()); } var restaurantType = new RestaurantType { RestaurantTypeName = nameRequest.RestaurantTypeName }; var entity = _dbContext.RestaurantType.Add(restaurantType); _dbContext.SaveChanges(); return(SupplyResponse.Ok(entity.Entity)); }
public SupplyResponse RemoveRestaurantManager(int id, [FromBody] IntIdRequest idRequest) { if (id == 0 || idRequest.Id == 0) { return(SupplyResponse.RequiredFieldEmpty()); } var restaurantManager = _dbContext.RestaurantManager.SingleOrDefault(p => p.RestaurantId == id && p.UserId == idRequest.Id); if (restaurantManager == null) { return(SupplyResponse.NotFound("restaurant manager", idRequest.Id + "<->" + id)); } _dbContext.RestaurantManager.Remove(restaurantManager); _dbContext.SaveChanges(); return(SupplyResponse.Ok()); }
public SupplyResponse RemoveRestaurantType(int id) { if (id == 0) { return(SupplyResponse.RequiredFieldEmpty()); } var restaurantType = _dbContext.RestaurantType.SingleOrDefault(p => p.RestaurantTypeId == id); if (restaurantType == null) { return(SupplyResponse.NotFound("restaurant type", "" + id)); } _dbContext.RestaurantType.Remove(restaurantType); _dbContext.SaveChanges(); return(SupplyResponse.Ok()); }