public async Task <ActionResult> Create(ManufacturerRequestViewModel request)
        {
            var result = await _client.PostManufacturer(request);

            var newViewModel = await result.Content.ReadAsAsync <ManufacturerRequestViewModel>();

            if (result.IsSuccessStatusCode)
            {
                if (Request.Files.Count > 0 &&
                    _validImageExtensions.Contains(System.IO.Path.GetExtension(Request.Files[0].FileName), System.StringComparer.OrdinalIgnoreCase))
                {
                    var image      = System.Drawing.Image.FromStream(Request.Files[0].InputStream);
                    var logoResult = await _client.PostManufacturerLogo(newViewModel.ManufacturerId, image);
                }

                TempData["SuccessAlert"] = $"The '{ request.Name }' manufacturer was successfully created!";
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                ModelState.AddModelError(string.Empty, _genericErrorMessage);
            }

            return(View(request));
        }
        public void Create_ShouldReturnView_WithEmptyModel()
        {
            // ARRANGE
            var clientMoq      = GetMoqClient(Enumerable.Empty <ManufacturerViewModel>());
            var controller     = new HomeController(clientMoq.Object);
            var expectedResult = new ManufacturerRequestViewModel();

            // ACT
            var result = controller.Create() as System.Web.Mvc.ViewResult;

            // ASSERT
            result.Model.Should().BeEquivalentTo(expectedResult);
        }
        public async Task <ActionResult> Update(ManufacturerRequestViewModel request)
        {
            var result = await _client.PutManufacturer(request.ManufacturerId, request);

            if (result.IsSuccessStatusCode)
            {
                TempData["SuccessAlert"] = "The manufacturer was successfully updated!";
            }
            else
            {
                ModelState.AddModelError(string.Empty, _genericErrorMessage);
            }

            return(View(request));
        }
        public async Task <ActionResult> Update(int id = -1)
        {
            if (id < 0)
            {
                return(new HttpStatusCodeResult(System.Net.HttpStatusCode.BadRequest, "Mandatory argument was not specified"));
            }

            ManufacturerRequestViewModel request = null;

            var response = await _client.GetManufacturer(id);

            if (response.IsSuccessStatusCode)
            {
                request = await response.Content.ReadAsAsync <ManufacturerRequestViewModel>();
            }
            else
            {
                ModelState.AddModelError(string.Empty, _genericErrorMessage);
            }

            return(View(request));
        }