Exemplo n.º 1
0
        public KitDto UpdateKit(string parentKitSku, KitDto model)
        {
            var oldKit = _context.kits.FirstOrDefault(x => x.ParentKitSKU == parentKitSku);

            // create a new Kit if it doesn't exist
            if (oldKit == null)
            {
                var kit = Mapper.Map <KitDto, kit>(model);
                _context.kits.Add(kit);
            }
            else
            {
                //otherwise, update the kit info
                _context.Entry(oldKit).CurrentValues.SetValues(model);
            }

            // update too the product's IsKit
            var product = _context.products.FirstOrDefault(x => x.EisSKU == model.ParentKitSKU);

            if (product != null)
            {
                product.IsKit = model.IsKit;
            }

            // then, save all the changes
            _context.SaveChanges();

            return(model);
        }
Exemplo n.º 2
0
        public JsonResult _UpdateKit(string parentKitSku, KitDto model)
        {
            model = _service.UpdateKit(parentKitSku, model);

            return(Json(model, JsonRequestBehavior.AllowGet));
        }