public async Task <Network> CreateNetworkAsync(NetworkItemViewModel networkModel) { var network = new Network { Caption = networkModel.Caption, Id = Guid.NewGuid(), MerchantUsers = new List <ApplicationUser>(), ProductCategory = _context.ProductCategories.FirstOrDefault(item => item.Id == networkModel.ProductCategoryId) }; if (networkModel.LogoImage != null) { using (var memoryStream = new MemoryStream()) { await networkModel.LogoImage.CopyToAsync(memoryStream); if (memoryStream != null) { network.LogoImage = memoryStream.ToArray(); } } } _context.Add(network); await _context.SaveChangesAsync(); return(network); }
public async Task <NetworkItemViewModel> GetNetworkProductCategoryListItemViewModelAsync() { var networkModel = new NetworkItemViewModel(); networkModel.ProductCategories = GetSelectListProductCategories(); return(networkModel); }
public async Task <IActionResult> Edit(Guid id, NetworkItemViewModel networkModel) { if (id != networkModel.Id) { return(NotFound()); } if (ModelState.IsValid) { try { await _service.UpdateNetworkAsync(networkModel); } catch (DbUpdateConcurrencyException) { if (!NetworkExists(networkModel.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } networkModel.ProductCategories = _service.GetSelectListProductCategories(); return(View(networkModel)); }
public Network ConvertFromViewModelToNetwork(NetworkItemViewModel networkModel) { var network = new Network() { Id = networkModel.Id, Caption = networkModel.Caption, LogoImage = networkModel.LogoImageView }; return(network); }
public async Task <IActionResult> Create(NetworkItemViewModel networkModel) { if (ModelState.IsValid) { await _service.CreateNetworkAsync(networkModel); return(RedirectToAction(nameof(Index))); } networkModel.ProductCategories = _service.GetSelectListProductCategories(); return(View(networkModel)); }
public NetworkItemViewModel ConvertFromNetworkToViewModel(Network network) { var networkModel = new NetworkItemViewModel() { Id = network.Id, Caption = network.Caption, LogoImageView = network.LogoImage, ProductCategoryName = network.ProductCategory?.Caption }; return(networkModel); }
public async Task <NetworkItemViewModel> GetNetworkItemViewModelAsync(Guid Id) { var network = await _context.Networks.Include(item => item.ProductCategory) .SingleOrDefaultAsync(m => m.Id == Id); if (network == null) { return(null); } var networkModel = new NetworkItemViewModel { Id = network.Id, Caption = network.Caption, LogoImageView = network.LogoImage, ProductCategories = GetSelectListProductCategories(), ProductCategoryId = network.ProductCategory.Id, ProductCategoryName = network.ProductCategory.Caption }; return(networkModel); }
public async Task UpdateNetworkAsync(NetworkItemViewModel networkModel) { var network = await GetNetwork(networkModel.Id); network.Caption = networkModel.Caption; network.ProductCategory = _context.ProductCategories.FirstOrDefault(item => item.Id == networkModel.ProductCategoryId); if (networkModel.LogoImage != null) { using (var memoryStream = new MemoryStream()) { await networkModel.LogoImage.CopyToAsync(memoryStream); if (memoryStream != null) { network.LogoImage = memoryStream.ToArray(); } } } _context.Update(network); await _context.SaveChangesAsync(); }