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); } }
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)); }
public ActionResult Create(CreateBrandViewModel model) { var brand = new DataAccess.Brand(); brand.Name = model.Name; brand.Country = model.Country; repo.Create(brand); return(RedirectToAction("Index")); }
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); }
public IActionResult Register([FromBody] CreateBrandViewModel brand) { if (!ModelState.IsValid) { return(BadResponse()); } _brandAppService.Register(brand); return(Response(brand)); }
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")); }
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)); }
public ActionResult Create() { var brand = new CreateBrandViewModel(); return(View(brand)); }
public int Create(CreateBrandViewModel model) { return(_brand.Create(_mapper.Map <Brand>(model))); }