コード例 #1
0
 public IActionResult DeleteItem(Guid id)
 {
     try
     {
         _itemService.DeleteItem(id);
     }
     catch (NullReferenceException e)
     {
         return(BadRequest());
     }
     return(NoContent());
 }
コード例 #2
0
        public IActionResult DeleteItem(int id)
        {
            int status = _itemRepository.DeleteItem(id);

            if (status > 0)
            {
                return(Ok());
            }
            else
            {
                return(BadRequest(new { message = "Item not deleted from cart. Please try again!" }));
            }
        }
コード例 #3
0
        public ActionResult Delete(int id)
        {
            if (id > 0)
            {
                Items items = _itemsService.GetItemDataById(id);

                if (items != null)
                {
                    _itemsService.DeleteItem(items);
                }
            }
            return(RedirectToAction("List"));
        }
コード例 #4
0
        public IActionResult Delete([FromRoute] int id)
        {
            string         email          = Request.Headers["Email"];
            string         password       = Request.Headers["Password"];
            StatusResponse statusResponse = new StatusResponse();

            if (String.IsNullOrEmpty(email) || String.IsNullOrEmpty(password))
            {
                return(BadRequest(_itemHelper.response(false, 500, "User can not authenticate please check email and password")));
            }

            UserManager user = _userManagerService.AuthenticateUser(email, password);

            if (user == null)
            {
                return(BadRequest(_itemHelper.response(false, 500, "User model is empty")));
            }

            //var userList = _userManagerService.GetAllUsers();
            if (id <= 0)
            {
                return(BadRequest(_itemHelper.response(false, 500, "Id is not valid")));
            }

            Items item = _itemsService.GetItemDataById(id);

            if (item == null)
            {
                return(BadRequest(_itemHelper.response(false, 500, "Item model is empty")));
            }

            item.IsActive     = false;
            item.ModifiedBy   = id;
            item.ModifiedDate = DateTime.UtcNow;

            _itemsService.DeleteItem(item);

            return(Ok(_itemHelper.response(true, 200)));
        }
コード例 #5
0
        public static void DeleteMultipleItems(IItemsService svc)
        {
            Console.WriteLine("Would you like to delete items as a batch?");
            bool batchDelete = Console.ReadLine().StartsWith("y", StringComparison.OrdinalIgnoreCase);
            var  allItems    = new List <int>();

            bool deleteAnother = true;

            while (deleteAnother == true)
            {
                Console.WriteLine("Items");
                Console.WriteLine("Enter the ID number to delete");
                Console.WriteLine("*******************************");
                var items = svc.ListInventory();
                items.ForEach(x => Console.WriteLine($"ID: {x.Id} | {x.Name}"));
                Console.WriteLine("*******************************");
                if (batchDelete && allItems.Any())
                {
                    Console.WriteLine("Items scheduled for delete");
                    allItems.ForEach(x => Console.Write($"{x},"));
                    Console.WriteLine();
                    Console.WriteLine("*******************************");
                }
                int id = 0;

                if (int.TryParse(Console.ReadLine(), out id))
                {
                    var itemMatch = items.FirstOrDefault(x => x.Id == id);
                    if (itemMatch != null)
                    {
                        if (batchDelete)
                        {
                            if (!allItems.Contains(itemMatch.Id))
                            {
                                allItems.Add(itemMatch.Id);
                            }
                        }
                        else
                        {
                            Console.WriteLine($"Are you sure you want to delete the item {itemMatch.Id}-{itemMatch.Name}");
                            if (Console.ReadLine().StartsWith("y", StringComparison.OrdinalIgnoreCase))
                            {
                                svc.DeleteItem(itemMatch.Id);
                                Console.WriteLine("Item Deleted");
                            }
                        }
                    }
                }

                Console.WriteLine("Would you like to delete another item?");
                deleteAnother = Console.ReadLine().StartsWith("y", StringComparison.OrdinalIgnoreCase);

                if (batchDelete && !deleteAnother)
                {
                    Console.WriteLine("Are you sure you want to delete the following items: ");
                    allItems.ForEach(x => Console.Write($"{x},"));
                    Console.WriteLine();
                    if (Console.ReadLine().StartsWith("y", StringComparison.OrdinalIgnoreCase))
                    {
                        svc.DeleteItems(allItems);
                        Console.WriteLine("Items Deleted");
                    }
                }
            }
        }