Ejemplo n.º 1
0
        public async Task <Provider> CreateProviderAsync(ProviderItemViewModel providerModel)
        {
            var provider = new Provider
            {
                Name        = providerModel.Name,
                Id          = Guid.NewGuid(),
                RetailUsers = new List <ApplicationUser>()
            };

            if (providerModel.LogoImage != null)
            {
                using (var memoryStream = new MemoryStream())
                {
                    await providerModel.LogoImage.CopyToAsync(memoryStream);

                    if (memoryStream != null)
                    {
                        provider.LogoImage = memoryStream.ToArray();
                    }
                }
            }
            _context.Add(provider);
            await _context.SaveChangesAsync();

            return(provider);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Edit(Guid id, ProviderItemViewModel providerModel)
        {
            if (id != providerModel.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    await _service.UpdateProviderAsync(providerModel);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProviderExists(providerModel.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(providerModel));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create(ProviderItemViewModel providerModel)
        {
            if (ModelState.IsValid)
            {
                await _service.CreateProviderAsync(providerModel);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(providerModel));
        }
Ejemplo n.º 4
0
        public Provider ConvertFromViewModelToProvider(ProviderItemViewModel providerModel)
        {
            var provider = new Provider()
            {
                Id        = providerModel.Id,
                Name      = providerModel.Name,
                LogoImage = providerModel.LogoImageView
            };

            return(provider);
        }
Ejemplo n.º 5
0
        public ProviderItemViewModel ConvertFromProviderToViewModel(Provider provider)
        {
            var providerModel = new ProviderItemViewModel()
            {
                Id            = provider.Id,
                Name          = provider.Name,
                LogoImageView = provider.LogoImage
            };

            return(providerModel);
        }
Ejemplo n.º 6
0
        public async Task <ProviderItemViewModel> GetProviderItemViewModelAsync(Guid Id)
        {
            var provider = await _context.Providers
                           .SingleOrDefaultAsync(m => m.Id == Id);

            if (provider == null)
            {
                return(null);
            }
            var providerModel = new ProviderItemViewModel
            {
                Id            = provider.Id,
                Name          = provider.Name,
                LogoImageView = provider.LogoImage
            };

            return(providerModel);
        }
Ejemplo n.º 7
0
        public async Task UpdateProviderAsync(ProviderItemViewModel providerModel)
        {
            var provider = await GetProvider(providerModel.Id);

            provider.Name = providerModel.Name;
            if (providerModel.LogoImage != null)
            {
                using (var memoryStream = new MemoryStream())
                {
                    await providerModel.LogoImage.CopyToAsync(memoryStream);

                    if (memoryStream != null)
                    {
                        provider.LogoImage = memoryStream.ToArray();
                    }
                }
            }
            _context.Update(provider);
            await _context.SaveChangesAsync();
        }