Esempio n. 1
0
        /// <summary>
        /// Deletes the cartproduct that matches the given cartproduct ID from the database
        /// </summary>
        /// <param name="cartProductId">The ID of the cartproduct</param>
        /// <returns>Task result</returns>
        public async Task RemoveProduct(int cartProductId)
        {
            CartProduct cartProductToDelete = await _storeContext.CartProducts.FindAsync(cartProductId);

            _storeContext.Remove(cartProductToDelete);
            await _storeContext.SaveChangesAsync();
        }
Esempio n. 2
0
        /// <summary>
        /// Deletes the cart with the given cartId from the database
        /// </summary>
        /// <param name="cartId">The ID of the cart to delete</param>
        /// <returns>Task result</returns>
        public async Task RemoveCartByID(int cartId)
        {
            Cart cartToDelete = await _storeContext.Carts.FindAsync(cartId);

            _storeContext.Remove(cartToDelete);
            await _storeContext.SaveChangesAsync();
        }
Esempio n. 3
0
        /// <summary>
        /// creates ability for the admin to delete the order
        /// </summary>
        /// <param name="id">the id of the order that wants to be deleted</param>
        /// <returns></returns>
        public async Task DeleteOrder(int id)
        {
            Order order = await _storeContext.Orders.FindAsync(id);

            _storeContext.Remove(order);
            await _storeContext.SaveChangesAsync();
        }
Esempio n. 4
0
        public IActionResult Delete(string id)
        {
            bool deleteResult = false;
            var  existUser    = Task.Run(async() => await _userManager.FindByIdAsync(id)).Result;

            if (existUser == null)
            {
                return(Json(new { deleteResult }));
            }

            var address = _context.Addresses.FirstOrDefault(el => el.Id == existUser.AddressId);

            _context.Remove(address);
            //Task.Run(async () => await _context.SaveChangesAsync());

            if (existUser.Avatar != AvatarUserDefault)
            {
                string DelPath = Path.Combine(_hostEnvironment.WebRootPath, "Images/UserImages", existUser.Avatar);
                System.IO.File.Delete(DelPath);
            }
            var identityResult = Task.Run(async() => await _userManager.DeleteAsync(existUser)).Result;

            deleteResult = identityResult.Succeeded;

            return(Json(new { deleteResult }));
        }
Esempio n. 5
0
        public int DeleteOrderDetail(int OrderId, int ProductId)
        {
            var OrderDetail = _context.OrderDetails.FirstOrDefault(el =>
                                                                   el.OrderId == OrderId &&
                                                                   el.ProductId == ProductId);

            _context.Remove(OrderDetail);
            return(_context.SaveChanges());
        }
        public int DeleteOrder(int id)
        {
            var order = _context.Orders.FirstOrDefault(el => el.Id == id);

            if (order == null)
            {
                return(-1);
            }
            _context.Remove(order);

            return(_context.SaveChanges());
        }
Esempio n. 7
0
        public async Task <Unit> Handle(DeleteApiKeyRequest request, CancellationToken cancellationToken)
        {
            var apikey = await _storeDbContext
                         .ApiKeys
                         .Where(f => f.Name == request.Name)
                         .SingleOrDefaultAsync(cancellationToken);

            if (apikey != null)
            {
                var permission = await _storeDbContext.Permissions
                                 .Where(p => p.SubjectId == apikey.Key && p.Kind == SubjectType.Application)
                                 .SingleOrDefaultAsync();

                _storeDbContext.Remove(permission);
                _storeDbContext.Remove(apikey);

                await _storeDbContext.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }

            Log.ApiKeyNotExist(_logger, request.Name);
            throw new InvalidOperationException($"The ApiKey with identifier {request.Name} does not exist and can't be deleted.");
        }
Esempio n. 8
0
        public void CanDeleteEntityInDb()
        {
            int existingId = 1;

            using (StoreDbContext context = new StoreDbContext(options))
            {
                var entity = context.Products.FirstOrDefault(x => x.ID == existingId);
                context.Remove(entity);
                context.SaveChanges();
            }

            using (StoreDbContext context = new StoreDbContext(options))
            {
                var entityCount = context.Products.Count();
                Assert.Equal(0, entityCount);
            }
        }
Esempio n. 9
0
        public async Task <Unit> Handle(DeleteTagRequest request, CancellationToken cancellationToken)
        {
            var featureTag = await _storeDbContext.FeatureTagEntities
                             .Where(ft => ft.FeatureEntityId == request.FeatureId && ft.TagEntity.Name == request.Tag)
                             .SingleOrDefaultAsync(cancellationToken);

            if (featureTag != null)
            {
                _storeDbContext.Remove(featureTag);

                await _storeDbContext.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }

            Log.FeatureTagNotExist(_logger, request.FeatureId.ToString(), request.Tag);
            throw new InvalidOperationException($"The feature tag association between feature {request.FeatureId} and tag {request.Tag} does not exist.");
        }
Esempio n. 10
0
        public string DeleteUser(string id)
        {
            try
            {
                using (dbContext = new StoreDbContext())
                {
                    var entity = dbContext.Users.FirstOrDefault(x => x.Id == id);

                    dbContext.Remove(entity);
                    dbContext.SaveChanges();
                    return("");
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
        public async Task <Unit> Handle(DeleteToggleRequest request, CancellationToken cancellationToken)
        {
            var toggle = await _storeDbContext
                         .Toggles
                         .Where(t => t.Id == request.ToggleId)
                         .SingleOrDefaultAsync(cancellationToken);

            if (toggle != null)
            {
                _storeDbContext.Remove(toggle);
                await _storeDbContext.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }

            Log.ToggleNotExist(_logger, request.ToggleId.ToString());
            throw new InvalidOperationException($"Toggle with id {request.ToggleId} does not exist in the store.");
        }
        public async Task <Unit> Handle(DeleteApiKeyRequest request, CancellationToken cancellationToken)
        {
            var apikey = await _storeDbContext
                         .ApiKeys
                         .Where(f => f.Id == request.ApiKeyId)
                         .SingleOrDefaultAsync(cancellationToken);

            if (apikey != null)
            {
                _storeDbContext.Remove(apikey);
                await _storeDbContext.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }

            Log.ApiKeyNotExist(_logger, request.ApiKeyId.ToString());
            throw new InvalidOperationException($"The ApiKey with identifier {request.ApiKeyId} does not exist and can't be deleted.");
        }
Esempio n. 13
0
        public IActionResult Delete(int id)
        {
            // Look for the item we are deleting
            var @signup = _db.Event.Find(id);

            // Return 404 Not Found if the item isn't in the database
            if (@signup == null)
            {
                return(NotFound());
            }

            // Product exists, so let's remove it
            _db.Remove(@signup);
            _db.SaveChanges();

            // Return the deleted item with 200 OK
            return(Ok(@signup));
        }
        public async Task <Unit> Handle(DeleteProductRequest request, CancellationToken cancellationToken)
        {
            var product = await _storeDbContext
                          .Products
                          .Where(p => p.Id == request.ProductId)
                          .SingleOrDefaultAsync(cancellationToken);

            if (product != null)
            {
                _storeDbContext.Remove(product);

                await _storeDbContext.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }

            Log.ProductNotExist(_logger, request.ProductId.ToString());
            throw new InvalidOperationException($"The product with identifier {request.ProductId} does not exist.");
        }
Esempio n. 15
0
        public async Task <Unit> Handle(DeleteFlagRequest request, CancellationToken cancellationToken)
        {
            var feature = await _storeDbContext
                          .Features
                          .Where(f => f.Id == request.FeatureId)
                          .Include(f => f.Toggles)
                          .SingleOrDefaultAsync(cancellationToken);

            if (feature != null)
            {
                _storeDbContext.Remove(feature);
                await _storeDbContext.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }

            Log.FeatureNotExist(_logger, request.FeatureId.ToString());
            throw new InvalidOperationException("Feature does not exist in the store.");
        }
Esempio n. 16
0
        public async Task <Unit> Handle(DeleteFeatureRequest request, CancellationToken cancellationToken)
        {
            var feature = await _storeDbContext
                          .Features
                          .Include(f => f.ProductEntity)//-> this is only needed for "history"
                          .Include(f => f.FeatureStates)
                          .Where(f => f.Name == request.FeatureName && f.ProductEntity.Name == request.ProductName)
                          .SingleOrDefaultAsync(cancellationToken);

            if (feature != null)
            {
                _storeDbContext.Remove(feature);
                await _storeDbContext.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }

            Log.FeatureNotExist(_logger, request.FeatureName);
            throw new InvalidOperationException("Feature does not exist in the store.");
        }
Esempio n. 17
0
        public async Task <bool> Handle(DeleteProductCommand request, CancellationToken cancellationToken)
        {
            try
            {
                Product lv_product = _storeDbContext.Product.Find(request.Id);
                bool    isSucces   = false;
                if (lv_product != null)
                {
                    _storeDbContext.Remove(lv_product);
                    await _storeDbContext.SaveChangesAsync();

                    isSucces = true;
                }

                return(isSucces);
            }
            catch (Exception e)
            {
                throw new Exception($"Cannot update Product #{request.Id} in the store because {e.Message}.");
            }
        }
Esempio n. 18
0
        public async Task <Unit> Handle(DeleteToggleRequest request, CancellationToken cancellationToken)
        {
            var toggle = await _storeDbContext
                         .Toggles
                         .Include(t => t.FeatureEntity)
                         .ThenInclude(t => t.ProductEntity) // only for history works!
                         .Include(t => t.Parameters)
                         .Where(t => t.FeatureEntity.Name == request.FeatureName && t.FeatureEntity.ProductEntity.Name == request.ProductName && t.Type == request.ToggleType)
                         .SingleOrDefaultAsync(cancellationToken);

            if (toggle != null)
            {
                _storeDbContext.Remove(toggle);
                await _storeDbContext.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }

            Log.ToggleNotExist(_logger, request.ToggleType);
            throw new InvalidOperationException($"Toggle with id {request.ToggleType} does not exist in the store.");
        }
Esempio n. 19
0
        public bool Handler(DeleteProductCommand command)
        {
            try
            {
                bool isExist = false;
                if (command.Id > 0)
                {
                    Product lv_product = _storeDbContext.Product.Find(command.Id);
                    if (lv_product != null)
                    {
                        isExist = true;
                        _storeDbContext.Remove(lv_product);
                        _storeDbContext.SaveChanges();
                    }
                }

                return(isExist);
            }
            catch (Exception e)
            {
                throw new Exception($"Cannot delete Product with Id #{command.Id} in the store because {e.Message}.");
            }
        }
Esempio n. 20
0
 public void Delete(T entity)
 {
     _context.Remove(entity);
     Save();
 }