コード例 #1
0
        public async Task Delete(int id)
        {
            var remove = await _brandRepository.GetById(id);

            _brandRepository.Delete(remove);
            await _brandRepository.Commit();
        }
コード例 #2
0
        public void Delete(int id)
        {
            var entity = _brandRepository.GetById(id);

            _brandRepository.Delete(entity);
            _unitofwork.Commit();
        }
コード例 #3
0
        public async Task <IActionResult> Delete(int id)
        {
            var location = GetControllerActionName();

            try
            {
                logger.LogInfo($"{location}: Delete Brand with id {id}");
                if (id < 1)
                {
                    logger.LogWarn($"{location}: Delete Brand with id {id} failed with bad data");
                    return(BadRequest());
                }
                var isExists = await brandRepository.IsExists(id);

                if (!isExists)
                {
                    logger.LogWarn($"{location}: Brand with id {id} not found");
                    return(NotFound());
                }
                var brand = await brandRepository.GetById(id);

                var isSuccess = await brandRepository.Delete(brand);

                if (!isSuccess)
                {
                    return(InternalError($"{location}: Delete Brand with id {id} failed"));
                }
                logger.LogInfo($"{location}: Delete Brand with id {id} successful");
                return(NoContent());
            }
            catch (Exception e)
            {
                return(InternalError($"{location}: {e.Message} - {e.InnerException}"));
            }
        }
コード例 #4
0
        public async Task <Response> Delete(int idBrand)
        {
            Response response = new Response();

            if (idBrand < 0)
            {
                response.Errors.Add("ID Inválido!");
            }
            if (response.HasErrors())
            {
                return(response);
            }
            else
            {
                response = await _iBrandRepository.Delete(idBrand);

                if (!response.Success)
                {
                    return(response);
                }
                else
                {
                    //Logger
                }
            }
        }
コード例 #5
0
ファイル: DeleteBrandCommand.cs プロジェクト: Emad-Sayed/DDD
            public async Task <MediatR.Unit> Handle(DeleteBrandCommand request, CancellationToken cancellationToken)
            {
                // get brand by id
                var brandFromRepo = await _brandRepository.FindByIdAsync(request.BrandId);

                if (brandFromRepo == null)
                {
                    throw new BrandNotFoundException(request.BrandId);
                }

                if (brandFromRepo.Products.Count > 0)
                {
                    throw new BrandContainsProductsException(request.BrandId);
                }

                // we call delete brand to rase delete brand event to sync with algolia
                brandFromRepo.Delete();

                // update brand with the new unit deleted
                _brandRepository.Delete(brandFromRepo);

                // save changes in the database and rase BrandUpdated event
                await _brandRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken);

                return(MediatR.Unit.Value);
            }
コード例 #6
0
        public async Task <Response> Delete(int idBrand)
        {
            Response response = new Response();

            if (idBrand < 0)
            {
                response.Errors.Add("ID Inválido!");
            }
            if (response.HasErrors())
            {
                return(response);
            }
            else
            {
                try
                {
                    return(response = await _iBrandRepository.Delete(idBrand));
                }
                catch (Exception ex)
                {
                    //_log.Info(response.Errors);
                    _log.Error(ex + "\nStackTrace: " + ex.StackTrace);
                    response.Errors.Add("DataBase error, contact the system owner");
                    return(response);
                }
            }
        }
コード例 #7
0
ファイル: BrandService.cs プロジェクト: lqt1912/LivelCMS
        public void Delete(Guid id)
        {
            var entity = brandRepository.GetById(id);

            brandRepository.Delete(entity);
            brandRepository.SaveChanges();
        }
コード例 #8
0
 /// <summary>
 /// Only deletes the brand if there are no references that depend on it.
 /// </summary>
 /// <param name="brandId"></param>
 /// <returns></returns>
 public bool DeleteBrand(int brandId)
 {
     try
     {
         var brandToDelete = _brandRepository.FindOne(x => x.Id == brandId);
         _brandRepository.Delete(brandToDelete);
         _brandRepository.Persist();
         Log.Debug("Brand '{0}' with Id '{1}' deleted.", brandToDelete.BrandName, brandToDelete.Id);
         return(true);
     }
     catch (Exception e)
     {
         Log.Error(string.Format("Failed to delete brand with Id '{0}'", brandId), e);
         return(false);
     }
 }
コード例 #9
0
        public async Task <ActionResult> Delete(int id)
        {
            try
            {
                var exist = await this._brandRepository.GetOneAsyn(id);

                if (exist == null)
                {
                    return(NotFound($"No Brand found with this id {id}."));
                }


                var data = await _brandRepository.Delete(id);

                if (data == false)
                {
                    return(BadRequest("This brand could not be removed."));
                }

                return(Ok("Brand removed."));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
コード例 #10
0
        public void Delete(int brandId)
        {
            Brands brand = GetById(brandId);

            _brandRepository.Delete(brand);
            _unitOfWork.Complete();
        }
コード例 #11
0
        protected void gvBrandDetails_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            try
            {
                Label lblBrandID            = (Label)gvBrandDetails.Rows[e.RowIndex].FindControl("lblBrandID");
                int   brandid               = int.Parse(lblBrandID.Text);
                var   CategoryBrandMappings = mappingRepo.Find(m => m.BrandId == brandid);
                if (CategoryBrandMappings != null)
                {
                    foreach (var item in CategoryBrandMappings)
                    {
                        mappingRepo.Delete(item.CategoryBrandMappingId);
                    }
                    brandRepo.Delete(brandid);
                }

                brandRepo.Save();

                BindData();
                ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Brand Sucessfully DELETED');", true);
            }
            catch (Exception)
            {
                lblmsgs.Visible = true;
                lblmsgs.Text    = "This Brand be use in system";
            }
            //conn.Open();
        }
コード例 #12
0
 public IActionResult Delete(int id)
 {
     if (brandRepository.Delete(id))
     {
         return(RedirectToAction("Index"));
     }
     return(View());
 }
コード例 #13
0
        public IActionResult Delete(int id)
        {
            var brand = _brandRepository.GetById(id);

            _brandRepository.Delete(brand);

            return(RedirectToAction(nameof(List)));
        }
コード例 #14
0
        public async Task <Unit> Handle(DeleteBrandCommand request, CancellationToken cancellationToken)
        {
            var brand = await _brandRepository.GetById(request.Id);

            await _brandRepository.Delete(brand);

            return(Unit.Value);
        }
コード例 #15
0
        public void Delete(int id)
        {
            if (id == 0)
            {
                throw new ArgumentException("The id can't be zero.");
            }

            _brandRepository.Delete(id);
        }
コード例 #16
0
        public async Task <bool> Handle(RemoveBrandCommand request, CancellationToken cancellationToken)
        {
            Domain.AggregatesModel.BrandAggregate.Brand brand = await _brandRepository.GetAsync(request.Id);

            _brandRepository.Delete(brand);
            var result = await _brandRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken);

            return(result);
        }
コード例 #17
0
        public IActionResult Delete(int id)
        {
            var result = brandRepository.Delete(id);

            if (result > 0)
            {
                return(RedirectToAction("Index", "Brand"));
            }
            return(View());
        }
コード例 #18
0
        public DeleteBrandResponse DeleteBrand(DeleteBandRequest deleteBandRequest)
        {
            var brand = brandRepository.FindBrandById(deleteBandRequest.Id);

            brandRepository.Delete(brand);
            var deletebrandresponse = new DeleteBrandResponse {
                Brand = messageMapper.MapToBrandDto(brand)
            };

            return(deletebrandresponse);
        }
コード例 #19
0
        public bool Delete(int id)
        {
            _proSer.DeleteByBrandId(id);
            _storeSer.DeleteByBrandId(id);
            var entity = _repo.GetById(id);

            if (entity == null)
            {
                return(false);
            }
            return(_repo.Delete(entity));
        }
コード例 #20
0
        public async Task <IActionResult> DeleteBrand(BrandCreationDto dto)
        {
            try
            {
                await _brandRepository.Delete(dto);

                return(Ok());
            }
            catch (Exception e)
            {
                return(NotFound("This Brand cannot be delete"));
            }
        }
コード例 #21
0
        public IActionResult Delete([FromRoute] int id, [FromRoute] int page = 1, [FromRoute] int pagesize = 10)
        {
            var brand = _brandRepo.GetBrand(id);

            if (brand == null)
            {
                return(NotFound());
            }

            _brandRepo.Delete(id);
            _brandRepo.Save();
            return(BrandsList(page, pagesize));
        }
コード例 #22
0
        public async Task <ActionResultResponse> Delete(string tenantId, string id)
        {
            var brandInfo = await _brandRepository.GetInfo(tenantId, id);

            if (brandInfo == null)
            {
                return(new ActionResultResponse(-1, _resourceService.GetString("Brand does not exists.")));
            }

            var result = await _brandRepository.Delete(tenantId, id);

            return(new ActionResultResponse(result, result <= 0 ? _resourceService.GetString("Something went wrong. Please contact with administrator.")
                    : _resourceService.GetString("Delete brand successful.")));
        }
コード例 #23
0
 public ActionResult Delete(BrandDTO entity)
 {
     try
     {
         Brand brand = brandRepository.GetById(entity.BrandID);
         brandRepository.Delete(brand);
         brandRepository.Save();
         return(Json(entity, JsonRequestBehavior.DenyGet));
     }
     catch (Exception e)
     {
         return(Json(false, JsonRequestBehavior.DenyGet));
     }
 }
コード例 #24
0
        public async Task <IActionResult> Delete(int id)
        {
            var _brandDelete = await _brandRepository.GetById(id);

            if (_brandDelete != null)
            {
                await _brandRepository.Delete(_brandDelete);

                return(Ok(_brandDelete));
            }
            else
            {
                return(Ok("La marca no existe"));
            }
        }
コード例 #25
0
        public DeleteBrandResponse DeleteBrand(DeleteBrandRequest request)
        {
            DeleteBrandResponse response = new DeleteBrandResponse();

            try
            {
                brandRepository.Delete(request.BrandId);
                response.Success = true;
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }
            return(response);
        }
コード例 #26
0
        public async Task <IActionResult> RemoveBrand(int id)
        {
            var brand = await _repo.GetBrand(id);

            if (brand == null)
            {
                return(NotFound("This brand doesn't exist."));
            }

            _repo.Delete(brand);

            if (await _repo.SaveAll())
            {
                return(NoContent());
            }

            return(BadRequest("It was not possible to remove the item."));
        }
コード例 #27
0
        protected override async void Delete(object sender, RoutedEventArgs e)
        {
            try
            {
                // Gets the brand to delete

                Brand ToBeDeleted = ((FrameworkElement)sender).DataContext as Brand;

                string messageboxTitle   = String.Format(LangResource.MBTitleDeleteObj, ToBeDeleted.Name);
                string messageboxContent = String.Format(LangResource.MBContentDeleteObj, LangResource.TheBrand.ToLower(), ToBeDeleted.Name);

                MessageBoxManager.Yes = LangResource.Yes;
                MessageBoxManager.No  = LangResource.No;
                MessageBoxManager.Register();

                if (MessageBox.Show(messageboxContent,
                                    messageboxTitle,
                                    MessageBoxButton.YesNo,
                                    MessageBoxImage.Warning)
                    == MessageBoxResult.Yes)
                {
                    MessageBoxManager.Unregister();

                    // Deletes the brand

                    _brandRepo.Delete(ToBeDeleted);
                    BrandsList.Remove(ToBeDeleted);

                    await _brandRepo.SaveChangesAsync();

                    // Refreshes the datagrid
                    BindData();
                }
                else
                {
                    MessageBoxManager.Unregister();
                }
            }
            catch (Exception)
            {
                MessageBox.Show(LangResource.ErrUpdateOverviewFailed);
                MessageBoxManager.Unregister();
            }
        }
コード例 #28
0
            /// <summary>
            /// Implementación de <see cref="IRequestHandler{TRequest, TResponse}.Handle(TRequest, CancellationToken)"/>
            /// </summary>
            public async Task <Unit> Handle(Request request, CancellationToken cancellationToken)
            {
                try
                {
                    if (request != null)
                    {
                        BrandInfo brand = new BrandInfo
                        {
                            Id   = request.Id,
                            Name = request.Name
                        };

                        await BrandRepository.Delete(brand);
                    }
                }
                catch (Exception ex)
                {
                    CommandExceptionHandler.Handle(ex, request);
                }
                return(Unit.Value);
            }
コード例 #29
0
        public async Task <IActionResult> Delete(int id)
        {
            try
            {
                var response = await _repository.Delete(id);

                if (response != 0)
                {
                    return(Ok("Deleted successfully"));
                }
                else
                {
                    return(BadRequest("An error ocurred, contact IT Staff"));
                }
            }
            catch (Exception e)
            {
                //Log error
                Log.Error(e.Message);
                Log.Error(e.StackTrace);
                return(BadRequest("An error ocurred, contact IT Staff"));
            }
        }
コード例 #30
0
ファイル: BrandsController.cs プロジェクト: vvash/CarCatalog
        public ActionResult DeleteConfirmed(int id)
        {
            CarBrand brand = _brandRepository.GetBrandById(id);

            if (brand == null)
            {
                return(HttpNotFound());
            }

            if (!brand.Models.Any())
            {
                var opStatus = new OperationStatus {
                    Status = true, Message = "Brand deleted"
                };
                try
                {
                    _brandRepository.Delete(brand);
                }
                catch (Exception exp)
                {
                    opStatus = OperationStatus.CreateFromExeption("Error deleting brand car.", exp);
                }

                TempData["OperationStatus"] = opStatus;
            }
            else
            {
                TempData["OperationStatus"] = new OperationStatus()
                {
                    Status  = true,
                    Message = "You must delete all models for this brand first"
                }
            };

            return(RedirectToAction("Index"));
        }
    }