Ejemplo n.º 1
0
        public async Task UpdateCategory(CategoriesForUpdate categoryToUpdate)
        {
            var serializedCustomerToUpdate = JsonConvert.SerializeObject(categoryToUpdate);

            var request = new HttpRequestMessage(HttpMethod.Put,
                                                 $"{apiRoute}/{categoryToUpdate.CategoryId}");

            request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(mediaType));
            request.Content = new StringContent(serializedCustomerToUpdate);
            request.Content.Headers.ContentType = new MediaTypeWithQualityHeaderValue(mediaType);

            var response = await _httpClient.SendAsync(request);

            response.EnsureSuccessStatusCode();
        }
Ejemplo n.º 2
0
		//public async Task<IActionResult> Edit(int id, [Bind("Id,CategoryId,CategoryName,Description,Picture64")] Categories categories)
		public async Task<IActionResult> Edit(int categoryId, [FromForm] CategoriesForUpdate category, IFormFile imgFile)
		{
            if (categoryId != category.CategoryId)
                return NotFound();

            if (ModelState.IsValid)
            {
                try
                {
					if (imgFile == null)
					{
						category.Picture = TmpPicture
											.Find(r => r.Id == category.CategoryId.ToString() )
											.TmpPicture;
					}
					else
					{
						var newImgFile = await Utilities.ConvertPictureToBytes(imgFile);
						category.Picture = newImgFile;
					}

					await _serviceCategories.UpdateCategory(category);
					//TmpPicture = new byte[0];
					var TmpPic = TmpPicture
								 .Find(r => r.Id == category.CategoryId.ToString());

					TmpPicture.Remove(TmpPic);
				}
                catch (DbUpdateConcurrencyException)
                {
                    if (await CategoryExists(category.CategoryId) == false)
                        return NotFound();
                    else
                        throw;
                }
				//return RedirectToAction(nameof(Index));
				return RedirectToAction("Details", new { categoryId = categoryId });
			}
            return View(category);
        }