Example #1
0
        public async Task <IActionResult> PutProducts(int id, Products products)
        {
            if (id != products.ProductId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Example #2
0
 public void AddItem(IQueryable <Item> updates)
 {
     foreach (var r in updates)
     {
         if (r.Ptag == null || r.Ptag == "")
         {
             continue;
         }
         History record        = new History(r);
         int     unixTimestamp = (int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
         record.Time = unixTimestamp.ToString();
         // update
         if (db.Items.Any(item => item.Ptag == r.Ptag))
         {
             db.Items.Attach(r);
             var entry = db.Entry(r);
             entry.Property(e => e.Custodian).IsModified = true;
             entry.Property(e => e.Room).IsModified      = true;
             entry.Property(e => e.Bldg).IsModified      = true;
             entry.Property(e => e.SortRoom).IsModified  = true;
         }
         else       // add new item
         {
             db.Items.Add(r);
         }
         // add new history record
         db.Histories.Add(record);
     }
 }
        public async Task <IActionResult> PutStock(int id, StockDTO stockDTO)
        {
            if (id != stockDTO.ID)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task <IActionResult> PutTransaction(int id, TransactionDTO transactionDto)
        {
            if (id != transactionDto.ID)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Example #5
0
        public string Take(string label)
        {
            object[] result = new object[2];

            try
            {
                Inventory item = _dbContext.Inventory.Where(l => l.Label == label && l.IsDeleted == false).First();
                if (item != null)
                {
                    item.IsDeleted = true;
                    _dbContext.Inventory.Attach(item);
                    _dbContext.Entry(item).State = System.Data.EntityState.Modified;
                    _dbContext.SaveChanges();
                    result[0] = "Item taken from inventory.";
                    result[1] = item;
                    NotificationsController.MessageCallback(string.Format("The item '{0}' (ID:{1}) has been taken from the inventory.", item.Label, item.ID.ToString()));
                }
                else
                {
                    result[0] = "Item not found.";
                    result[1] = "Unable to find item '" + label + "'";
                }
                return(JsonConvert.SerializeObject(result));
            }
            catch
            {
                result[0] = "Bad Request";
                result[1] = "Item not found.";
                return(JsonConvert.SerializeObject(result));
            }
        }
Example #6
0
 public ActionResult Edit([Bind(Include = "Id,Brand,Model,Production_Year,Color,Status,Category")] Car car)
 {
     if (ModelState.IsValid)
     {
         db.Entry(car).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(car));
 }
 public ActionResult Edit([Bind(Include = "CatID,Name,Description,Picture")] Categories categories)
 {
     if (ModelState.IsValid)
     {
         db.Entry(categories).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(categories));
 }
 public ActionResult Edit([Bind(Include = "CompanyName,Phone")] Shippers shippers)
 {
     if (ModelState.IsValid)
     {
         db.Entry(shippers).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(shippers));
 }
Example #9
0
 public ActionResult Edit([Bind(Include = "CompanyName,ContactName,ContactTitle,Address,City,Region,PostalCode,Country,Phone,fax")] Customers customers)
 {
     if (ModelState.IsValid)
     {
         db.Entry(customers).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(customers));
 }
Example #10
0
 public ActionResult Edit([Bind(Include = "Id,Name,CategoryId")] Product product)
 {
     if (ModelState.IsValid)
     {
         db.Entry(product).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CategoryId = new SelectList(db.Categories, "Id", "Name", product.CategoryId);
     return(View(product));
 }
 public ActionResult Edit([Bind(Include = "TerritoryID,TerritoryDesc,RegionID")] Territories territories)
 {
     if (ModelState.IsValid)
     {
         db.Entry(territories).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.RegionID = new SelectList(db.Regions, "RegionID", "RegionDesc", territories.RegionID);
     return(View(territories));
 }
Example #12
0
 public ActionResult Edit([Bind(Include = "EmployeeID,LastName,FirstName,Title,Birthdate,Hiredate,Address,City,Region,PostalCode,Country,HomePhone,Extension,Photo,ReportsToID")] Employees employees)
 {
     if (ModelState.IsValid)
     {
         db.Entry(employees).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ReportsToID = new SelectList(db.Employees, "EmployeeID", "LastName", employees.ReportsToID);
     return(View(employees));
 }
Example #13
0
 public ActionResult Edit([Bind(Include = "ProductID,ProductName,UnitPrice,SupplierID,CategoryID,QuantityPerUnit,UnitsInStock,UnitsInOrder,ReorderLevel,Discontinued")] Products products)
 {
     if (ModelState.IsValid)
     {
         db.Entry(products).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CategoryID = new SelectList(db.Categories, "CatID", "Name", products.CategoryID);
     ViewBag.SupplierID = new SelectList(db.Suppliers, "SupplierID", "CompanyName", products.SupplierID);
     return(View(products));
 }
 public ActionResult Edit([Bind(Include = "ProductID,OrderID,UnitPrice,Quanity,Discount")] OrderDetails orderDetails)
 {
     if (ModelState.IsValid)
     {
         db.Entry(orderDetails).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.OrderID   = new SelectList(db.Orders, "OrderID", "shipAddress", orderDetails.OrderID);
     ViewBag.ProductID = new SelectList(db.Products, "ProductID", "ProductName", orderDetails.ProductID);
     return(View(orderDetails));
 }
 public ActionResult Edit([Bind(Include = "OrderID,OrderDate,CustID,EmployeeID,RequiredDate,ShippedDate,ShipVia,shipAddress,ShipCity,ShipRegion,ShipPostalCode,ShipCountry")] Orders orders)
 {
     if (ModelState.IsValid)
     {
         db.Entry(orders).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CustID     = new SelectList(db.Customers, "CustID", "CompanyName", orders.CustID);
     ViewBag.EmployeeID = new SelectList(db.Employees, "EmployeeID", "LastName", orders.EmployeeID);
     ViewBag.ShipVia    = new SelectList(db.Shippers, "ShipperID", "CompanyName", orders.ShipVia);
     return(View(orders));
 }
Example #16
0
        public async Task <ActionResult> PutCar(int id, Cars updatedCar)
        {
            if (id != updatedCar.Id || !ModelState.IsValid)
            {
                return(BadRequest());
            }
            else
            {
                _context.Entry(updatedCar).State = EntityState.Modified;
                await _context.SaveChangesAsync();

                return(NoContent());
            }
        }
Example #17
0
        /// <summary>
        /// If the request was approved, also need to update transfer history
        /// </summary>
        /// <param name="barcode"></param>
        /// <returns></returns>
        public async Task <ActionResult> Approve(string barcode)
        {
            if (barcode == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Transfer transfer = await db.Transfers.FindAsync(barcode);

            if (transfer == null)
            {
                return(HttpNotFound());
            }
            // remove from pending list
            db.Transfers.Remove(transfer);

            // update transfer status and save to all time requests
            transfer.Status = 1;
            db.AllTimeRequests.Add(new AllTimeRequest(transfer));

            Item item = await db.Items.FindAsync(barcode);

            if (item == null)
            {
                return(HttpNotFound());
            }
            // update the custodian
            item.Custodian = transfer.Receiver;

            // get a new history with new custodian (item was updated)
            History record = new History(item);

            record.Time = transfer.Time;

            // update existing entry in item table
            db.Items.Attach(item);
            var itemEntry = db.Entry(item);

            itemEntry.Property(e => e.Custodian).IsModified = true;

            // save the new record to history
            db.Histories.Add(record);

            // save all changes
            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
Example #18
0
 //public IEnumerable<TEntity> AddRange(IEnumerable<TEntity> entity)
 //{
 //    return _dbSet.AddRange(entity);
 //}
 public TEntity Update(TEntity entityToUpdate)
 {
     _dbSet.Attach(entityToUpdate);
     _context.Entry(entityToUpdate).State = EntityState.Modified;
     return(entityToUpdate);
 }