Exemple #1
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(_mapper.Map <ShippingPriceWeight>(ShippingPriceWeight)).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ShippingPriceWeightExists(ShippingPriceWeight.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Exemple #2
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                await Initialize();

                return(Page());
            }

            foreach (var item in ShopConfigModel)
            {
                var shopConfig = _mapper.Map <ApplicationCore.Entities.ShopConfig>(item);
                _context.Attach(shopConfig).State = EntityState.Modified;

                try
                {
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                }
            }
            return(RedirectToPage("./Index"));
        }
Exemple #3
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(CatalogReference).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CatalogReferenceExists(CatalogReference.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            //Check Reference Product

            if (OriginalReference != CatalogReference.ReferenceCatalogItemId)
            {
                //Delete reference
                var oldReference = await _context.CatalogReferences
                                   .SingleOrDefaultAsync(x =>
                                                         x.CatalogItemId == OriginalReference &&
                                                         x.ReferenceCatalogItemId == CatalogReference.CatalogItemId);

                _context.CatalogReferences.Remove(oldReference);

                //Create new reference
                var newReference = await _context.CatalogReferences
                                   .SingleOrDefaultAsync(x =>
                                                         x.CatalogItemId == CatalogReference.ReferenceCatalogItemId &&
                                                         x.ReferenceCatalogItemId == CatalogReference.CatalogItemId);

                if (newReference == null)
                {
                    _context.CatalogReferences.Add(
                        new CatalogReference(CatalogReference.ReferenceCatalogItemId, CatalogReference.LabelDescription, CatalogReference.CatalogItemId)
                        );
                }
                await _context.SaveChangesAsync();
            }
            else if (!OriginalLabelReference.Equals(CatalogReference.LabelDescription))
            {
                var catalogReference = await _context.CatalogReferences
                                       .SingleOrDefaultAsync(x =>
                                                             x.CatalogItemId == OriginalReference &&
                                                             x.ReferenceCatalogItemId == CatalogReference.CatalogItemId);

                catalogReference.UpdateLabel(CatalogReference.LabelDescription);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("/Products/Edit", new { id = CatalogReference.CatalogItemId }));
        }