Пример #1
0
        public IHttpActionResult PostItem(SaveItemVM vm)
        {
            var userId = User.Identity.GetUserId();

            if (_unit.User.IsAdmin(userId) || _unit.User.IsManager(userId))
            {
                _unit.Admin.SaveItem(vm);

                return(Ok());
            }
            return(Unauthorized());
        }
Пример #2
0
        public void SaveItem(SaveItemVM vm)
        {
            Item item = null;

            if (vm.Id > 0)
            {
                item = _db.Items.Where(v => v.Id == vm.Id).FirstOrDefault();

                if (vm.Name != null)
                {
                    item.Name = vm.Name;
                }
                if (vm.ImageUrl != null)
                {
                    item.ImageUrl = vm.ImageUrl;
                }
                if (vm.Price > 0)
                {
                    item.Price = vm.Price;
                }
                item.IsAlcohol = vm.IsAlcohol;
                if (vm.IsRetired)
                {
                    item.IsRetired = vm.IsRetired;
                }
            }
            else if (vm.CategoryId > 0)
            {
                item = new Item
                {
                    CategoryId = vm.CategoryId,
                    Name       = vm.Name,
                    ImageUrl   = vm.ImageUrl,
                    Price      = vm.Price,
                    IsAlcohol  = vm.IsAlcohol
                };

                _db.Items.Add(item);
            }

            _db.SaveChanges();
        }