Example #1
0
        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);
        }
Example #2
0
        public async Task <NetworkItemViewModel> GetNetworkProductCategoryListItemViewModelAsync()
        {
            var networkModel = new NetworkItemViewModel();

            networkModel.ProductCategories = GetSelectListProductCategories();
            return(networkModel);
        }
Example #3
0
        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));
        }
Example #4
0
        public Network ConvertFromViewModelToNetwork(NetworkItemViewModel networkModel)
        {
            var network = new Network()
            {
                Id        = networkModel.Id,
                Caption   = networkModel.Caption,
                LogoImage = networkModel.LogoImageView
            };

            return(network);
        }
Example #5
0
        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));
        }
Example #6
0
        public NetworkItemViewModel ConvertFromNetworkToViewModel(Network network)
        {
            var networkModel = new NetworkItemViewModel()
            {
                Id                  = network.Id,
                Caption             = network.Caption,
                LogoImageView       = network.LogoImage,
                ProductCategoryName = network.ProductCategory?.Caption
            };

            return(networkModel);
        }
Example #7
0
        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);
        }
Example #8
0
        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();
        }