public async Task <IActionResult> PutGetCategory([FromRoute] int id, [FromBody] GetCategory getCategory) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != getCategory.userId) { return(BadRequest()); } _context.Entry(getCategory).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!GetCategoryExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public void OnGet( [FromServices] GetProductsByCategoryName getProductsByCategoryName, [FromServices] GetCategory getCategory, string name) { Products = getProductsByCategoryName.Do(name); Category = getCategory.Do(name); }
public async Task <ActionResult <CategoryDto> > Get([FromRoute] GetCategory query) { var result = await _dispatcher.QueryAsync(query); if (result is null) { return(NotFound()); } return(result); }
public async Task <IActionResult> PostGetCategory([FromBody] GetCategory getCategory) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.GetCategory.Add(getCategory); await _context.SaveChangesAsync(); return(CreatedAtAction("GetGetCategory", new { id = getCategory.userId }, getCategory)); }
public async Task <List <Models.Category> > Handle(GetCategory message, CancellationToken cancellationToken) { var command = context.Categories.AsQueryable(); if (message.Id != null) { command = command.Where(m => m.Id == message.Id); } var result = await command.Select(x => mapper.Map <Models.Category>(x)).ToListAsync(cancellationToken); return(result); }
public object Get(GetCategory request) { var result = icategoryService.GetCategoryById(request.Id); if (result.Success) { return(result.Entity); } // STATUS CODE return(null); }
public async Task Get_ReturnsListAsync() { var queryHandler = new CategoryQueryHandler(BasicNeeds); var query = new GetCategory() { Id = null }; var actual = await queryHandler.Handle(query, CancellationToken.None); Assert.AreEqual(2, actual.Count); }
public IActionResult OnGet( [FromServices] GetCategory getCategory, string name) { Category = getCategory.Action(name.Replace("-", " ")); if (Category == null) { return(RedirectToPage("/Index")); } else { return(Page()); } }
public void OnGet(int?categId) { if (categId == null) { Category = new CategoryVMUI(); } else { var getCategory = new GetCategory(_context).Do(categId); Category = new CategoryVMUI { CategoryId = getCategory.CategoryId, Name = getCategory.Name, Photo = getCategory.Photo, }; } }
public object GetJson(GetCategory request) { using (var db = dbFactory.Open()) { var category = db.SelectByIds <Category>(new[] { request.Id }); if (category.Any()) { return(new CategoriesResponse { Status = "success", Data = category }); } else { throw HttpError.NotFound("Category does not exist."); } } }
public ActionResult GetCategory(int id) { try { Category category = repository.GetById(id); if (category == null) { return(NotFound()); } GetCategory getCategory = mapper.Map <GetCategory>(category); return(Ok(category)); } catch (Exception) { return(NotFound()); } }
/// <summary> /// Конструктор страницы заявок на ПС /// </summary> /// <param name="_so">Заявка на ПС</param> /// <param name="_servicemans">Список техников</param> /// <param name="_mounters">Список монтажников</param> public ServiceOrderFireAlarmViewModel(NewTest2ExtensionBase_ex _so, List <NewServicemanExtensionBase> _servicemans, List <NewMounterExtensionBase> _mounters) { ServiceOrderFireAlarm = _so; ServiceOrderFireAlarm.NewDate = ServiceOrderFireAlarm.NewDate.Value.AddHours(5); Servicemans = _servicemans; Mounters = _mounters; OpacityForm = 1; //WiresVisible = false; //ExtFieldsVisible = false; //EventsVisible = false; GetInfoByGuardObject.Execute(null); GetCategory.Execute(null); GetObjectNameCommand.Execute(null); App.Current.MainPage.HeightRequest = DeviceDisplay.MainDisplayInfo.Height; InfoImage = IconName("info"); ReorderImage = IconName("reorder"); EventImage = IconName("event"); CloseImage = IconName("close"); TransferImage = IconName("transfer"); PeopleImage = IconName("people"); }
public void Should_get_category() { // Arrange var command = new GetCategory { Id = 1 }; var entity = new Category { Id = 1, Name = "test category" }; var fakeRepo = new Mock <ICategoryRepository>(); fakeRepo.Setup(m => m.Find(command.Id)).Returns(entity); // Act var res = Task.Run(() => new GetCategoryHandler(fakeRepo.Object, _mapper).Handle(command, default)).Result; // Assert fakeRepo.Verify(x => x.Find(command.Id), Times.Once()); Assert.Equal(entity, res); }
public IActionResult GetCategory([FromServices] GetCategory getCategory, string name) { var categories = getCategory.Do(name); return(Ok(categories)); }
//http://localhost:34667/api/evolution/ public response Get() { GetCategory myGetCategory = new GetCategory(); return(myGetCategory.Get()); }
public void SincronizaProdutos() { RefreshToken(); var products = _productService.SearchProducts(categoryIds: null, pageSize: int.MaxValue, showHidden: true); ProductResponse[] GetProductResponse = null; ProductResponse ProductResponse = null; CategoryResponse[] CategoryResponse = null; var ContaAzulMiscSettings = _settingService.LoadSetting <ContaAzulMiscSettings>(); foreach (var item in products) { var product = new ProductMessage(); var categoria = "?name=Mercadoria para Revenda"; //busca a categoria no conta azul para obter o id: using (var getcategory = new GetCategory(ContaAzulMiscSettings.UseSandbox)) CategoryResponse = getcategory.CreateAsync(ContaAzulMiscSettings.access_token, categoria).ConfigureAwait(false).GetAwaiter().GetResult(); // var categoria = _categoryService.GetProductCategoryById(item.Id); product.name = item.Name; product.value = Math.Round(item.Price, 1); product.cost = Math.Round(item.ProductCost); product.available_stock = item.StockQuantity; product.net_weight = Math.Round(item.Weight, 3); product.category_id = CategoryResponse[0].id; product.gross_weight = Math.Round(item.Weight, 3); try { var filtro = "?name=" + item.Name; using (var getproduct = new GetProduct(ContaAzulMiscSettings.UseSandbox)) GetProductResponse = getproduct.CreateAsync(null, ContaAzulMiscSettings.access_token, filtro).ConfigureAwait(false).GetAwaiter().GetResult(); if (GetProductResponse.Count() > 0) { var productTable = _contaAzulProductService.GetProduct(GetProductResponse[0]); //caso ele não exista na tabela relacional do banco, insere e atualiza no conta azul if (productTable == null) { using (var productCreation = new ProductCreation(ContaAzulMiscSettings.UseSandbox)) ProductResponse = productCreation.CreateAsyncUpdate(product, GetProductResponse[0].id.ToString(), ContaAzulMiscSettings.access_token).ConfigureAwait(false).GetAwaiter().GetResult(); if (ProductResponse != null) { var productContaAzul = new ProductContaAzul(); productContaAzul.ContaAzulId = ProductResponse.id; productContaAzul.ProductId = item.Id; productContaAzul.DataCriacao = DateTime.Now; _contaAzulProductService.InsertProduct(productContaAzul); } } else {//caso já existe no banco, só verifica se houve alteração e faz o update no conta azul product.id = productTable.ContaAzulId.ToString(); var objetoContaAzul = JsonConvert.SerializeObject(GetProductResponse[0]); var objetoAtualizar = JsonConvert.SerializeObject(product); var data = objetoAtualizar.Equals(objetoContaAzul); if (!objetoAtualizar.Equals(objetoContaAzul)) { using (var productCreation = new ProductCreation(ContaAzulMiscSettings.UseSandbox)) ProductResponse = productCreation.CreateAsyncUpdate(product, productTable.ContaAzulId.ToString(), ContaAzulMiscSettings.access_token).ConfigureAwait(false).GetAwaiter().GetResult(); } } } else {//caso ele não exista no conta azul, faz a inserção dele no conta azul e no banco de dados var data2 = JsonConvert.SerializeObject(product); using (var productCreation = new ProductCreation(ContaAzulMiscSettings.UseSandbox)) ProductResponse = productCreation.CreateAsync(product, ContaAzulMiscSettings.access_token).ConfigureAwait(false).GetAwaiter().GetResult(); if (ProductResponse != null) { var productContaAzul = new ProductContaAzul(); productContaAzul.ContaAzulId = ProductResponse.id; productContaAzul.ProductId = item.Id; productContaAzul.DataCriacao = DateTime.Now; _contaAzulProductService.InsertProduct(productContaAzul); } } } catch (Exception ex) { _logger.Error(ex.Message, ex); } } }
public IActionResult GetCategory( int id, [FromServices] GetCategory getCategory) => Ok(getCategory.Action(id));
public IActionResult GetCategory( Guid id, [FromServices] GetCategory getCategory) => Ok(getCategory.Do(id));
public async Task <CategoryModel> GetCategoryAsync([FromBody] GetCategory getCategory) { return(await _mediator.Send(getCategory)); }
public async Task <IActionResult> Get([FromRoute] GetCategory query) => Select(await Dispatcher.QueryAsync(query));
public Task <Category> Handle(GetCategory message, CancellationToken cancellationToken) { return(categoryRepository.Find(message.Id)); }