public async Task <ICommandResult> Handle(UserDeleteCommand command)
        {
            //FFV
            command.Validate();
            if (command.Invalid)
            {
                return(new GenericCommandResult(false, HttpStatusCode.BadRequest, command.Notifications));
            }

            var _verify = await _userRepository.GetById(command.Id);

            if (_verify == null)
            {
                return(new GenericCommandResult(false, HttpStatusCode.NotFound, _verify));
            }

            User _entity = new User();

            _entity.Id = command.Id;

            var _result = await _contextRepository.Delete(_entity);

            //retorna o resultado
            if (!_result)
            {
                return(new GenericCommandResult(false, HttpStatusCode.BadRequest, _result));
            }

            return(new GenericCommandResult(true, HttpStatusCode.OK, _result));
        }
Beispiel #2
0
        public ActionResult Edit(CatalogModels model)
        {
            if (ModelState.IsValid)
            {
                Catalog catalog = _catalog.GetById(model.catalog.Id);

                try
                {
                    if (model.catalog != null)
                    {
                        catalog.Code        = model.catalog.Code;
                        catalog.Description = model.catalog.Description;
                        _catalog.Save();
                    }

                    if (model._SelectedProducts != null)
                    {
                        foreach (var sel in model._SelectedProducts)
                        {
                            ProductsCatalogs procals = _productscatalogs.GetAll().Where(c => c.Catalog.Id == model.catalog.Id).Where(c => c.Product.Id == sel.Id).FirstOrDefault();

                            if (sel.Checked == 0 && procals != null)
                            {
                                _productscatalogs.Delete(procals);
                                _productscatalogs.Save();
                            }
                            else if (sel.Checked == 1 && procals == null)
                            {
                                ProductsCatalogs procalen = new ProductsCatalogs();
                                Product          pro      = _product.GetById(sel.Id);
                                procalen.Product = pro;
                                procalen.Catalog = catalog;
                                _productscatalogs.Insert(procalen);
                                _productscatalogs.Save();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    //...
                }
            }

            return(RedirectToAction("Index"));
        }
Beispiel #3
0
        public ActionResult Delete(int id)
        {
            try
            {
                List <ProductsCatalogs> procals = _productscatalogs.GetAll().Where(p => p.Catalog.Id == id).ToList();
                foreach (var el in procals)
                {
                    _productscatalogs.Delete(el);
                }
                _productscatalogs.Save();
                Catalog catalog = _catalog.GetById(id);
                _catalog.Delete(catalog);
                _catalog.Save();
            }
            catch (Exception ex)
            {
            }

            return(RedirectToAction("Index"));
        }
Beispiel #4
0
        public async Task <ICommandResult> Handle(TruckDeleteCommand command)
        {
            command.Validate();
            if (command.Invalid)
            {
                return(new GenericCommandResult(false, HttpStatusCode.BadRequest, command.Notifications));
            }

            var _verify = await _truckRepository.GetById(command.Id);

            if (_verify == null)
            {
                return(new GenericCommandResult(false, HttpStatusCode.NotFound, _verify));
            }

            var _result = await _contextRepository.Delete(_verify);

            if (!_result)
            {
                return(new GenericCommandResult(false, HttpStatusCode.BadRequest, _result));
            }

            return(new GenericCommandResult(true, HttpStatusCode.OK, _result));
        }