Esempio n. 1
0
        public async Task <ApplicationResult <BrandDto> > Create(CreateBrandViewModel model)
        {
            try
            {
                var user = await _userManager.FindByIdAsync(model.CreatedById);

                Brand mapBrand = _mapper.Map <Brand>(model);
                mapBrand.CreatedById   = model.CreatedById;
                mapBrand.CreatedBy     = user.UserName;
                mapBrand.SubCategoryId = model.SubCategoryId;
                _context.Brands.Add(mapBrand);
                await _context.SaveChangesAsync();

                ApplicationResult <BrandDto> result = new ApplicationResult <BrandDto>
                {
                    Result    = _mapper.Map <BrandDto>(mapBrand),
                    Succeeded = true
                };

                return(result);
            }
            catch (Exception e)
            {
                ApplicationResult <BrandDto> result = new ApplicationResult <BrandDto>();
                result.Succeeded    = false;
                result.ErrorMessage = e.Message;
                return(result);
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> Create(CreateBrandViewModel model)
        {
            var returnErrorModel = model;

            if (ModelState.IsValid)
            {
                model.CreatedById = User.FindFirst(ClaimTypes.NameIdentifier).Value;
                var result = await _brandService.Create(model);

                if (result.Succeeded)
                {
                    return(RedirectToAction("Index"));
                }
                ModelState.AddModelError(string.Empty, result.ErrorMessage);
            }
            var subCategoryList = await _subCategoryService.GetAll();

            ViewBag.subCategoryDDL = subCategoryList.Result.Select(x => new SelectListItem
            {
                Selected = false,
                Text     = x.CategoryName,
                Value    = x.Id.ToString()
            }).ToList();
            return(View(returnErrorModel));
        }
Esempio n. 3
0
        public ActionResult Create(CreateBrandViewModel model)
        {
            var brand = new DataAccess.Brand();

            brand.Name    = model.Name;
            brand.Country = model.Country;
            repo.Create(brand);

            return(RedirectToAction("Index"));
        }
Esempio n. 4
0
        public async Task <CommandResult <Guid> > CreateBrand([FromBody] CreateBrandViewModel viewModel)
        {
            var createBrandModel = _mapper.Map <WebSiteBrandModel>(viewModel);
            var result           = await _brandManager.CreateBrand(createBrandModel);

            if (result.IsSucceeded)
            {
                this.ConfirmFileAdded(createBrandModel.ImageFile);
            }
            return(result);
        }
Esempio n. 5
0
        public IActionResult Register([FromBody] CreateBrandViewModel brand)
        {
            if (!ModelState.IsValid)
            {
                return(BadResponse());
            }

            _brandAppService.Register(brand);

            return(Response(brand));
        }
Esempio n. 6
0
        public IActionResult AddB(CreateBrandViewModel createModel)
        {
            BrandViewModel brand  = new BrandViewModel();
            HttpClient     client = new HttpClient();
            var            result = client.PostAsJsonAsync("https://localhost:44309/api/brand", createModel).Result;

            if (result.IsSuccessStatusCode)
            {
                brand = result.Content.ReadAsAsync <BrandViewModel>().Result;
            }
            return(RedirectToAction("GetAllBrands"));
        }
Esempio n. 7
0
        public async Task <IActionResult> Create(CreateBrandViewModel createBrandViewModel)
        {
            if (ModelState.IsValid)
            {
                Brand createBrand = _iMapper.Map <Brand>(createBrandViewModel);
                bool  isAdd       = await _iBrandManager.Create(createBrand);

                if (isAdd)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ViewBag.ErrorMessage = "Failed to Save Brand";
                }
            }

            return(View(createBrandViewModel));
        }
Esempio n. 8
0
        public ActionResult Create()
        {
            var brand = new CreateBrandViewModel();

            return(View(brand));
        }
Esempio n. 9
0
 public int Create(CreateBrandViewModel model)
 {
     return(_brand.Create(_mapper.Map <Brand>(model)));
 }