public GenericApiResponseWithResult <IEnumerable <ItemCategory> > GetCategories() { var result = new GenericApiResponseWithResult <IEnumerable <ItemCategory> >(); var categoryItems = new List <ItemCategory>(); try { categoryItems = _context.ItemCategories.ToList(); }catch (Exception ex) { result.Success = false; result.Error = (int)ErrorCodes.InternalServerError; result.Message = ex.Message; } result.Success = true; result.Result = categoryItems; return(result); }
public GenericApiResponseWithResult <ItemGroup> SaveGroup([FromBody] ItemGroup group) { var result = new GenericApiResponseWithResult <ItemGroup>(); result.Success = true; try { var itemExists = _context.ItemGroups.Count(x => x.Id == group.Id) > 0; if (!itemExists) { group.CreationUserId = "oobeso"; group.CreationDate = DateTime.Now; group.IsDeleted = false; _context.Add(group); } else { var gr = _context.ItemGroups.FirstOrDefault(x => x.Id == group.Id); group.UpdateDate = DateTime.Now; group.UpdateUserId = "oobeso"; Sync(gr, group); } _context.SaveChanges(); } catch (Exception ex) { result.Success = false; result.Error = (int)ErrorCodes.InternalServerError; result.Message = ex.Message; } if (result.Success) { result.Result = group; } return(result); }
public GenericApiResponseWithResult <ItemCategory> SaveCategory([FromBody] ItemCategory category) { var result = new GenericApiResponseWithResult <ItemCategory>(); result.Success = true; try { var itemExists = _context.ItemCategories.Count(x => x.Id == category.Id) > 0; if (!itemExists) { category.CreationUserId = "oobeso"; category.CreationDate = DateTime.Now; category.IsDeleted = false; _context.Add(category); } else { var cat = _context.ItemCategories.FirstOrDefault(x => x.Id == category.Id); category.UpdateDate = DateTime.Now; category.UpdateUserId = "oobeso"; Sync(cat, category); } _context.SaveChanges(); }catch (Exception ex) { result.Success = false; result.Error = (int)ErrorCodes.InternalServerError; result.Message = ex.Message; } if (result.Success) { result.Result = category; } return(result); }
public GenericApiResponseWithResult <IEnumerable <RetailCategoryListItem> > GetRetailData(string ticketType) { var result = new GenericApiResponseWithResult <IEnumerable <RetailCategoryListItem> >(); var categoriesResult = new List <RetailCategoryListItem>(); try { foreach (var category in _context.ItemCategories) { var categoryResult = new RetailCategoryListItem(); categoryResult.Id = category.Id; categoryResult.Name = category.Name; categoryResult.ButtonColor = category.ButtonColor; categoryResult.Beverage = category.Beverage; categoryResult.TextColor = category.TextColor; var groupsResult = new List <RetailGroupListItem>(); var groups = _context.ItemGroups.Where(x => x.CategoryId == category.Id); foreach (var group in groups) { var groupResult = new RetailGroupListItem(); groupResult.Id = group.Id; groupResult.Name = group.Name; groupResult.CategoryId = group.CategoryId; groupResult.ButtonColor = group.ButtonColor; groupResult.TextColor = group.TextColor; groupResult.SortOrder = group.SortOrder; var itemsResult = new List <RetailItemListItem>(); var items = _context.RetailItems.Where(x => x.GroupId == group.Id); foreach (var item in items) { var itemResult = new RetailItemListItem(); itemResult.Id = item.Id; itemResult.Description = item.Description; itemResult.Cost = item.BuyPrice; itemResult.SortOrder = item.SortOrder; var modifierGroups = _context.ItemModifierGroupItems.Where(x => x.RetailItemId == item.Id) .Join(_context.ItemModifierGroups, relation => relation.ItemModifierGroupId, grp => grp.Id, (rel, grp) => grp); var modifierGroupsResult = new List <RetailItemModifierGroup>(); foreach (var modGroup in modifierGroups) { var modifierGroupResult = new RetailItemModifierGroup(); modifierGroupResult.Id = modGroup.Id; modifierGroupResult.Name = modGroup.Name; modifierGroupResult.Required = modGroup.Required; modifierGroupResult.WorkflowOrder = modGroup.SortOrder; var modifiers = _context.ItemModifiers.Where(x => x.GroupId == modGroup.Id); var modifiersResult = new List <RetailItemModifier>(); foreach (var modifier in modifiers) { var modifierResult = new RetailItemModifier(); modifierResult.Id = modifier.Id; modifierResult.Name = modifier.Name; modifierResult.Cost = modifier.Price; modifierResult.SortOrder = modifier.SortOrder; modifiersResult.Add(modifierResult); } modifierGroupResult.Modifiers = modifiersResult.ToArray(); modifierGroupsResult.Add(modifierGroupResult); } itemResult.ModifierGroups = modifierGroupsResult.ToArray(); itemsResult.Add(itemResult); } groupResult.Items = itemsResult.ToArray(); groupsResult.Add(groupResult); } categoryResult.Groups = groupsResult.ToArray(); categoriesResult.Add(categoryResult); } }catch (Exception ex) { result.Success = false; result.Error = (int)ErrorCodes.InternalServerError; result.Message = ex.Message; } result.Success = true; result.Result = categoriesResult.ToArray(); return(result); }