Exemplo n.º 1
0
        public async Task <ActionResult> Create(AddBrandViewModel request)
        {
            if (!ModelState.IsValid)
            {
                Alert($"Invalid Request.", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(View());
            }
            try
            {
                var addBrandRequest = new AddBrandRequest {
                    Name = request.Name, Description = request.Description
                };
                var result = await _brandService.Create(addBrandRequest);

                if (!result.Success)
                {
                    Alert($"{result.Message}", NotificationType.info, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                    return(View());
                }
                Alert($"Brand Created Successfully", NotificationType.success, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception ex)
            {
                Alert($"Error! {ex.Message}.", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(View());
            }
        }
Exemplo n.º 2
0
        public ActionResult AddBrand(AddBrandViewModel vm)
        {
            tblBrandsService service = new tblBrandsService();

            service.addBrand(vm.newBrand);
            return(RedirectToAction("CarIndex"));
        }
Exemplo n.º 3
0
        public ActionResult AddBrand()
        {
            tblBrandsService  service = new tblBrandsService();
            AddBrandViewModel vm      = new AddBrandViewModel();

            vm.brands = service.getBrands();
            return(View(vm));
        }
Exemplo n.º 4
0
        public IActionResult Add()
        {
            var model = new AddBrandViewModel
            {
                Brand = new Brand()
            };

            return(View(model));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Add(AddBrandViewModel brandModel)
        {
            //TODO: make brand add friendly error page
            if (!ModelState.IsValid)
            {
                this.TempData.AddFailureMessage(string.Format(FailureAddItemMessage, brandModel.Name));
                return(this.RedirectToAction(nameof(Index)));
                //return this.BadRequest();
            }

            await brandService.AddBrandAsync(brandModel.Name);

            this.TempData.AddSuccessMessage(string.Format(SuccessAddItemMessage, brandModel.Name));
            return(this.RedirectToAction(nameof(Index)));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> AddBrand(AddBrandViewModel model)
        {
//            ModelState.AddModelError("keyName", "Form is not valid");

            if (ModelState.IsValid)
            {
                var size = model.BrandImage.Length;

                if (size > 5242880)
                {
                    ModelState.AddModelError("OverLength", "File Size is not greater than 5MB");
                    return(View(model));
                }

                var imageId = await UploadImages(new List <IFormFile>
                {
                    model.BrandImage
                });

                var brand = new AddBrandDTO
                {
                    BrandImage   = imageId[0],
                    Slug         = model.Name.URLFriendly(),
                    ContactEmail = model.ContactEmail,
                    ContactName  = model.ContactName,
                    ContactPhone = model.ContactPhone,
                    ContactTitle = model.ContactTitle,
                    Name         = model.Name
                };

                using (var client = _restClient.CreateClient(User))
                {
                    using (
                        var response = await client.PostAsync("/api/brand",
                                                              new StringContent(JsonConvert.SerializeObject(brand), Encoding.UTF8,
                                                                                "application/json")))
                    {
                        if (response.StatusCode == HttpStatusCode.Created)
                        {
                            return(RedirectToAction("Brands"));
                        }
                    }
                }
            }

            return(View(model));
        }
        public IActionResult AddBrand(AddBrandViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return View($"{BrandsViewFolder}/Add.cshtml", model);
            }

            BaseWebServiceResponse response = _brandWebService.Add(model);
            TempData[BrandActionName] = JsonConvert.SerializeObject(response);

            if (!response.ActionSuccessful)
            {
                model.ActionResponse = response;
                return View($"{BrandsViewFolder}/Add.cshtml", model);
            }
            
            return RedirectToAction("Index", "Brands");
        }
        public BaseWebServiceResponse Add(AddBrandViewModel model)
        {
            var brandDto        = mapper.Map <AddBrandViewModel, BrandDTO>(model);
            var brandNameExists = _brandService.BrandNameExists(brandDto);

            var response = new BaseWebServiceResponse
            {
                ActionSuccessful = !brandNameExists,
                Error            = brandNameExists ?
                                   new ErrorServiceViewModel()
                {
                    Name    = "Brand Name",
                    Message = "Brand Name is already in use."
                } :
                null
            };

            if (response.Error != null)
            {
                return(response);
            }

            var brandAdded = _brandService.Add(brandDto);

            if (!brandAdded)
            {
                response.ActionSuccessful = false;
                response.Error            = brandAdded ?
                                            null :
                                            new ErrorServiceViewModel()
                {
                    Name    = "Brand",
                    Message = "There was a problem creating the Brand. We have been notified of the error but please try again."
                };
            }

            response.SuccessMessage   = "Brand added successfully!";
            response.ActionSuccessful = true;
            return(response);
        }
Exemplo n.º 9
0
        public IActionResult Add(Brand brand)
        {
            var model = new AddBrandViewModel()
            {
                Brand = brand
            };

            if (brand.BrandName == null)
            {
                return(View(model));
            }

            var result = _brandService.Add(brand);

            if (!result.Success)
            {
                return(RedirectToAction("InternalError", "Error", new { errorMessage = result.Message }));
            }

            TempData.Add(TempDataTypes.BrandInfo, Messages.BrandAdded);
            return(RedirectToAction("Index", "Brand"));
        }
        public IActionResult Add(AddBrandViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var        newName = Guid.NewGuid();
            var        path    = _hostEnvironment.WebRootPath + "/Uploads/" + newName + model.Image.FileName;
            FileStream stream  = new FileStream(path, FileMode.Create);

            model.Image.CopyTo(stream);
            stream.Close();

            var brand = new Brand()
            {
                Name      = model.Name,
                ImagePath = newName + model.Image.FileName
            };

            _unitOfWork.BrandRepository.Add(brand);
            _unitOfWork.Complete();
            return(RedirectToAction(nameof(List)));
        }