예제 #1
0
        public async Task <IActionResult> PutUser(int id, User user)
        {
            if (id != user.ID)
            {
                return(BadRequest());
            }

            _context.Entry(user).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
예제 #2
0
        public ActionResult Edit(ProductEditViewModel productEdit)
        {
            //2018-05-31 - Ej kunna ändra på Quantity
            if (!ModelState.IsValid)
            {
                return(View(productEdit));
            }

            //Installera NUGET "valueinjecter"
            var product = Mapper.Map <Product>(productEdit);

            //var product = new Product
            //{
            //    Id = productEdit.Id,
            //    Name = productEdit.Name,
            //    Price = productEdit.Price,
            //    Category = productEdit.Category,
            //    Description = productEdit.Description,
            //};

            db.Entry(product).State = EntityState.Modified;
            db.Entry(product).Property(p => p.Quantity).IsModified = false;
            //E 2018-05-31 - Ej kunna ändra på Quantity

            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
예제 #3
0
        public async Task <IActionResult> PutWarehouseOrder(int id, int orderId, Order order)
        {
            if (orderId != order.ID || order.WarehouseID != id)
            {
                return(BadRequest());
            }

            _context.Entry(order).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!OrderExists(orderId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
예제 #4
0
        /// <inheritdoc />
        public Notification Update(Notification notification)
        {
            if (notification != null)
            {
                var storingNotification = _db.Notifications.Find(notification.Id);
                if (storingNotification != null)
                {
                    storingNotification.Update(notification);
                    _db.Entry(storingNotification).State = EntityState.Modified;
                    _db.SaveChanges();
                }
            }

            return(notification);
        }
예제 #5
0
        public async Task <IActionResult> PutInventory(int id, Inventory inventory)
        {
            if (id != inventory.ID)
            {
                return(BadRequest());
            }

            _context.Entry(inventory).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!InventoryExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok(inventory));
        }
예제 #6
0
        public async Task <IActionResult> PutSupplier(long id, Supplier supplier)
        {
            if (id != supplier.Id)
            {
                return(BadRequest());
            }

            _context.Entry(supplier).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SupplierExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok());
        }
예제 #7
0
        //Edit existing store
        public async Task <StoreModels> editStore(StoreModels store)
        {
            _db.Entry(store).State = EntityState.Modified;
            await _db.SaveChangesAsync();

            return(store);
        }
예제 #8
0
        public async Task <IActionResult> PutWheelChain(int id, WheelChain wheelChain)
        {
            if (id != wheelChain.ID)
            {
                return(BadRequest());
            }

            _context.Entry(wheelChain).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!WheelChainExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutCategory(long id, Category category)
        {
            if (id != category.Id)
            {
                return(BadRequest());
            }

            _context.Entry(category).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CategoryExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok());
        }
예제 #10
0
        public async Task <IActionResult> PutRoofRack(int id, RoofRack roofRack)
        {
            if (id != roofRack.ID)
            {
                return(BadRequest());
            }

            _context.Entry(roofRack).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RoofRackExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
예제 #11
0
        //Edit some laptop
        public async Task <LaptopModels> editLaptop(LaptopModels laptop)
        {
            _db.Entry(laptop).State = EntityState.Modified;
            await _db.SaveChangesAsync();

            return(laptop);
        }
예제 #12
0
        /// <summary>
        /// Editing existend good.
        /// </summary>
        /// <param name="objGood">Editable object</param>
        /// <returns>Operation is or not successful message.</returns>
        public string Edit(Good objGood)
        {
            //Returning message.
            string msg;

            try
            {
                //Edit good's data validation.
                if (ModelState.IsValid)
                {
                    using (_context = new WarehouseContext())
                    {
                        //Modifying changed good.
                        _context.Entry(objGood).State = EntityState.Modified;
                        _context.SaveChanges();
                        msg = "Good was changed";
                    }
                }
                else
                {
                    //validation is not successful
                    msg = "Wrong data for good";
                }
            }
            catch (Exception ex)
            {
                msg = "Error occured:" + ex.Message;
            }
            return(msg);
        }
예제 #13
0
        //Save this users details after editing

        public UserModels saveUser(UserModels userModels)
        {
            _db.Entry(userModels).State = EntityState.Modified;
            userModels.DateModified     = DateTime.Now;
            _db.SaveChanges();
            return(userModels);
        }
        public async Task <IActionResult> PutOrder(long id, Order order)
        {
            if (id != order.Id)
            {
                return(BadRequest());
            }

            var oldOrder = await _context.Orders
                           .AsNoTracking()
                           .Include(o => o.OrderProducts)
                           .Where(o => o.Id == id)
                           .FirstOrDefaultAsync();

            var listToDelete = oldOrder.OrderProducts;

            foreach (var item in listToDelete)
            {
                _context.Entry(item).State = EntityState.Deleted;
            }
            await _context.SaveChangesAsync();

            var listToAdd = order.OrderProducts;

            foreach (var item in listToAdd)
            {
                _context.OrderProducts.Add(item);
            }
            _context.Entry(order).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!OrderExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok());
        }
        public async Task <IActionResult> PutSupply(long id, Supply supply)
        {
            if (id != supply.Id)
            {
                return(BadRequest());
            }

            var oldSupply = await _context.Supplies
                            .AsNoTracking()
                            .Include(s => s.SupplyProducts)
                            .Where(s => s.Id == id)
                            .FirstOrDefaultAsync();

            var listToDelete = oldSupply.SupplyProducts;

            foreach (var item in listToDelete)
            {
                _context.Entry(item).State = EntityState.Deleted;
            }
            await _context.SaveChangesAsync();

            var listToAdd = supply.SupplyProducts;

            foreach (var item in listToAdd)
            {
                _context.SupplyProducts.Add(item);
            }
            _context.Entry(supply).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SupplyExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok());
        }
 public void Delete(Product product)
 {
     using (var dbContext = new WarehouseContext())
     {
         dbContext.Entry(product).State = EntityState.Deleted;
         dbContext.SaveChanges();
     }
 }
예제 #17
0
 public void Delete(Order order)
 {
     using (var dbContext = new WarehouseContext())
     {
         dbContext.Entry(order).State = EntityState.Deleted;
         dbContext.SaveChanges();
     }
 }
        public async Task <IActionResult> PutPosition(int id, [FromBody] Position item)
        {
            item.Id = id;
            _context.Entry(item).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(NoContent());
        }
        public void SaveModel(ProductModel productModel)
        {
            using (var dbContext = new WarehouseContext())
            {
                if (productModel.Id.HasValue)
                {
                    dbContext.Entry(productModel).State = EntityState.Modified;
                    dbContext.Entry(productModel.Manufacturer).State = EntityState.Modified;
                }
                else
                {
                    dbContext.ProductModels.Add(productModel);
                    dbContext.Entry(productModel.Manufacturer).State = EntityState.Modified;
                }

                dbContext.SaveChanges();
            }
        }
예제 #20
0
        /// <inheritdoc />
        public Client Update(Client client)
        {
            if (client != null)
            {
                _db.Entry(client).State = EntityState.Modified;
                _db.SaveChanges();
            }

            return(client);
        }
예제 #21
0
 public ActionResult Edit([Bind(Include = "ID,Brand,Make,Price,Count,FreeShipping")] Product product)
 {
     if (ModelState.IsValid)
     {
         db.Entry(product).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(product));
 }
예제 #22
0
 public ActionResult Edit([Bind(Include = "Id,Name,Price,Quantity,Category,Description")] Product product)
 {
     if (ModelState.IsValid)
     {
         db.Entry(product).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(product));
 }
예제 #23
0
        public async Task <IActionResult> Delete(int id)
        {
            Cargo cargo = new Cargo {
                ID = id
            };

            _db.Entry(cargo).State = EntityState.Deleted;
            await _db.SaveChangesAsync();

            return(RedirectToAction("Orders", "Warehouse"));
        }
예제 #24
0
        public void Save(Order order)
        {
            using (var dbContext = new WarehouseContext())
            {
                if (order.Id.HasValue)
                {
                    dbContext.Entry(order).State = System.Data.Entity.EntityState.Modified;
                    dbContext.Entry(order.ProductModel).State = EntityState.Modified;
                    dbContext.Entry(order.ProductModel.Manufacturer).State = EntityState.Modified;
                }
                else
                {
                    dbContext.Orders.Add(order);
                    dbContext.Entry(order.ProductModel).State = EntityState.Modified;
                    dbContext.Entry(order.ProductModel.Manufacturer).State = EntityState.Modified;
                }

                dbContext.SaveChanges();
            }
        }
예제 #25
0
        public async Task <IActionResult> Delete(int id)
        {
            Product product = new Product {
                ID = id
            };

            _db.Entry(product).State = EntityState.Deleted;
            await _db.SaveChangesAsync();

            return(RedirectToAction("Products", "Warehouse"));
        }
예제 #26
0
        public async Task <IActionResult> Delete(int id)
        {
            Customer customer = new Customer {
                ID = id
            };

            _db.Entry(customer).State = EntityState.Deleted;
            await _db.SaveChangesAsync();

            return(RedirectToAction("Customers", "Warehouse"));
        }
예제 #27
0
        public async Task <IActionResult> Delete(int id)
        {
            Position position = new Position {
                ID = id
            };

            _db.Entry(position).State = EntityState.Deleted;
            await _db.SaveChangesAsync();

            return(RedirectToAction("Positions", "Warehouse"));
        }
예제 #28
0
        public async Task <IActionResult> Delete(int id)
        {
            Storage storage = new Storage {
                ID = id
            };

            _db.Entry(storage).State = EntityState.Deleted;
            await _db.SaveChangesAsync();

            return(RedirectToAction("Storages", "Warehouse"));
        }
예제 #29
0
        public ActionResult Edit(ProductEditViewModel productEdit) //POCO (Entity)
        {
            if (!ModelState.IsValid)
            {
                return(View(productEdit));
            }

            var product = Mapper.Map <Product>(productEdit);

            //var product = new Product
            //{
            //    Id = productEdit.Id,
            //    Name = productEdit.Name,
            //    Category = productEdit.Category,
            //    Description = productEdit.Description,
            //    Price = productEdit.Price
            //};

            db.Entry(product).State = EntityState.Modified;
            db.Entry(product).Property(p => p.Quantity).IsModified = false;
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public async Task <IActionResult> Edit(int id, Products product)
        {
            if (id != product.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(product);

                    _context.Entry(product.Category).State = EntityState.Unchanged;

                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProductsExists(product.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            var allCategories = this._context.Category.ToList();

            this.ViewBag.Categories = allCategories;

            return(View(product));
        }