Esempio n. 1
0
        public MenuItemInfoOutput RemoveMenuItem([FromBody] MenuItemInfoInput input)
        {
            MenuItemInfoOutput output = new MenuItemInfoOutput();

            if (!string.IsNullOrEmpty(input.MenuItemId))
            {
                MenuItem       menuItem    = _db.MenuItems.Where(e => e.Id.Equals(input.MenuItemId)).FirstOrDefault();
                AspUserService userService = new AspUserService(_db, this);

                if (menuItem == null)
                {
                    output.Result = "DOES_NOT_EXIST";
                }
                else
                {
                    if (userService.IsStaff || menuItem.Menu.Vendor.Owner == userService.User)
                    {
                        menuItem.Deleted = true;
                        _db.SaveChanges();
                        output.Result = "OK";
                    }
                    else
                    {
                        output.Result = "NO_PRIVILEGE";
                    }
                }
            }
            else
            {
                output.Result = "INPUT_IS_NULL";
            }

            return(output);
        }
Esempio n. 2
0
        public MenuItemInfoOutput RetrieveListByMenuId([FromBody] MenuItemInfoInput input)
        {
            MenuItemInfoOutput output = new MenuItemInfoOutput();

            if (input == null)
            {
                output.Result = "INPUT_IS_NULL";
            }
            else
            {
                if (string.IsNullOrEmpty(input.MenuId))
                {
                    output.Result = "INPUT_IS_NULL";
                }
                else
                {
                    Menu menu = _db.Menus.Where(e => e.Id.Equals(input.MenuId) && e.Deleted == false).FirstOrDefault();
                    if (menu == null)
                    {
                        output.Result = "DOES_NOT_EXIST";
                    }
                    else
                    {
                        List <MenuItem>     menuItemList    = menu.MenuItems.Where(e => e.Deleted == false).OrderBy(e => e.Name).ToList();
                        List <MenuItemInfo> newMenuItemList = new List <MenuItemInfo>();
                        NumberFormatInfo    nfi             = new CultureInfo("ms-MY", false).NumberFormat;
                        nfi.CurrencyDecimalDigits = 2;

                        foreach (MenuItem item in menuItemList)
                        {
                            MenuItemInfo menuItem = new MenuItemInfo()
                            {
                                Id           = item.Id,
                                Name         = item.Name,
                                ShortDesc    = item.ShortDesc,
                                LongDesc     = item.LongDesc,
                                Price        = item.Price.ToString(),
                                DisplayPrice = item.Price.ToString("C", nfi),
                                WaitingTime  = item.WaitingTime.ToString("N1"),
                                ImgUrl       = item.ImgUrl
                            };
                            newMenuItemList.Add(menuItem);
                        }

                        output.MenuItemList = newMenuItemList;
                        output.MenuName     = menu.Name;
                        output.MenuId       = menu.Id;
                        output.Result       = "OK";
                    }
                }
            }
            return(output);
        }