public async Task UpdateBrandInfo(Guid brandId, BrandInfoModel model)
        {
            var url = UrlBuilder.UpdateBrandInfoUrl(brandId);

            var requestContent = new MultipartFormDataContent();

            requestContent.Add(new StringContent(model.Name), "name");
            requestContent.Add(new StringContent(model.Url), "url");
            if (!string.IsNullOrWhiteSpace(model.Description))
            {
                requestContent.Add(new StringContent(model.Description), "description");
            }
            if (model.Image != null)
            {
                var imageContent = new ByteArrayContent(model.Image.ToByteArray());
                imageContent.Headers.ContentType = MediaTypeHeaderValue.Parse(model.Image.ContentType);

                requestContent.Add(imageContent, "image", model.Image.FileName);
            }

            var response = await Client.PutAsync(url, requestContent);

            if (!response.IsSuccessStatusCode)
            {
                throw new ApplicationException($"Update brand {brandId} call ended with status code {response.StatusCode}");
            }
        }
        public async Task <IActionResult> Post([FromForm] BrandInfoModel model)
        {
            var brandId = await ControllerServices.CreateNewBrand(model);

            _logger.LogInformation("New brand created with id {brandId}", brandId);

            return(CreatedAtAction(nameof(Get), new { id = brandId }, brandId));
        }
        async Task CreateNewBrand(BrandInfoModel newBrand)
        {
            try
            {
                await Client.CreateNewBrand(newBrand);

                Navigation.NavigateTo("catalog/brands");
            }
            catch
            {
                errorRaised = true;
            }
        }
        public async Task <IActionResult> Put(Guid id, [FromForm] BrandInfoModel model)
        {
            if (id == Guid.Empty)
            {
                _logger.LogError("Empty brand id");
                return(BadRequest(nameof(id)));
            }

            await ControllerServices.UpdateBrandInfo(id, model);

            _logger.LogInformation("Info updated for brand with {brandId}", id);

            return(Ok());
        }
        protected override Task OnInitializedAsync()
        {
            context        = new EditContext(Model);
            editingEnabled = !Readonly;

            _originalModel = new BrandInfoModel
            {
                Description = Model.Description,
                Image       = Model.Image,
                Name        = Model.Name,
                Url         = Model.Url
            };

            return(base.OnInitializedAsync());
        }
 async Task UpdateBrandInfo(BrandInfoModel model)
 {
     try
     {
         await Client.UpdateBrandInfo(_BrandId, model);
     }
     catch
     {
         errorRaised = true;
     }
     finally
     {
         StateHasChanged();
     }
 }
        void Cancel()
        {
            Model = new BrandInfoModel
            {
                Description = _originalModel.Description,
                Image       = _originalModel.Image,
                Name        = _originalModel.Name,
                Url         = _originalModel.Url
            };

            if (Readonly)
            {
                editingEnabled = false;
            }

            StateHasChanged();
        }
        public async Task UpdateBrandInfo(Guid brandId, BrandInfoModel model)
        {
            var brandLogo = new Image {
                Data = new byte[0]
            };

            if (model.Image != null && model.Image.Length > 0)
            {
                brandLogo = new Image
                {
                    MimeType = model.Image.ContentType,
                    Data     = model.Image.ToByteArray()
                };
            }

            await Commands.UpdateBrandInfo(brandId, model.Name, model.Url, model.Description, brandLogo);
        }
        public async Task <Guid> CreateNewBrand(BrandInfoModel model)
        {
            var brandLogo = new Image {
                Data = new byte[0]
            };

            if (model.Image != null && model.Image.Length > 0)
            {
                brandLogo = new Image
                {
                    MimeType = model.Image.ContentType,
                    Data     = model.Image.ToByteArray()
                };
            }

            var brandId = await Commands.CreateNewBrand(model.Name, model.Url, model.Description, brandLogo);

            return(brandId);
        }