// GET: Brands/Details/5 public async Task <ActionResult> Details(Guid id) { var productDiscount = new BrandDetailsViewModel(); try { var result = await _brandService.FindById(id); if (!result.Success) { Alert($"Error! {result.Message}", NotificationType.info, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View(productDiscount)); } productDiscount.Code = result.Data.Code; productDiscount.Id = result.Data.Id; productDiscount.Name = result.Data.Name; productDiscount.Description = result.Data.Description; productDiscount.DateCreated = result.Data.CreatedAt; productDiscount.DateLastUpdated = result.Data.LastUpdated; return(View(productDiscount)); } catch (Exception ex) { Alert($"Error! {ex.Message}", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View(productDiscount)); } }
public async Task <ActionResult> Delete(Guid id, BrandDetailsViewModel request) { if (!ModelState.IsValid) { Alert("Bad Request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View()); } if (id == null) { Alert($"Invalid Request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View()); } try { var result = await _brandService.Delete(id); if (!result.Success) { Alert($"Error! {result.Message}", NotificationType.info, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View()); } Alert($"Brand Deleted Successfully", NotificationType.success, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(RedirectToAction(nameof(Index))); } catch { Alert($"Error Occurred While processing the request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View()); } }
// GET: Brands/Delete/5 public async Task <ActionResult> Delete(Guid id) { if (id == null) { Alert($"Invalid Request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View()); } var brand = new BrandDetailsViewModel(); try { var result = await _brandService.FindById(id); if (!result.Success) { Alert($"Error! {result.Message}", NotificationType.info, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View(brand)); } brand.Code = result.Data.Code; brand.Id = result.Data.Id; brand.Name = result.Data.Name; brand.Description = result.Data.Description; brand.DateCreated = result.Data.CreatedAt; brand.DateLastUpdated = result.Data.LastUpdated; return(View(brand)); } catch (Exception ex) { Alert($"Error! {ex.Message}", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View(brand)); } }
public IActionResult DeleteBrand(int id) { BrandDetailsViewModel brand = this.brandService.GetBrand(id); if (brand == null) { return(RedirectToAction(RedirectConstants.IndexSuffix)); } return(this.View(brand)); }
public async Task CheckIfGetBrandViewModelByIdAsyncWorksCorrectly() { this.SeedDatabase(); var expectedModel = new BrandDetailsViewModel { Id = this.firstBrand.Id, Name = this.firstBrand.Name, }; var viewModel = await this.brandsService.GetViewModelByIdAsync <BrandDetailsViewModel>(this.firstBrand.Id); var expectedObj = JsonConvert.SerializeObject(expectedModel); var actualResultObj = JsonConvert.SerializeObject(viewModel); Assert.Equal(expectedObj, actualResultObj); }
public ActionResult Details(int brandId) { var brandDto = _brandService.GetBrand(brandId); var modelsDto = _modelService.GetBrandModelsList(brandId); var model = new BrandDetailsViewModel { Brand = new BrandInfoViewModel { Id = brandDto.Id, Name = brandDto.Name }, BrandedModels = modelsDto .Select(m => new ModelInfoViewModel { Id = m.Id, Name = m.Name, BrandId = m.BrandId }) }; return(View(model)); }
public async Task <IActionResult> Remove(BrandDetailsViewModel brandViewModel) { await this.brandsService.DeleteByIdAsync(brandViewModel.Id); return(this.RedirectToAction("GetAll", "Brands", new { area = "Administration" })); }