Esempio n. 1
0
 public string Post(FormDataCollection postData)
 {
     object[] result = new object[2];
     try
     {
         object modelResult = Inventory.ValidateItem(postData.Get("label"), postData.Get("expiration_date"), postData.Get("type"));
         if (modelResult is string)
         {
             result[0] = "Invalid Request";
             result[1] = modelResult;
             return(JsonConvert.SerializeObject(result));
         }
         else
         {
             _dbContext.Inventory.Add((Inventory)modelResult);
             _dbContext.SaveChanges();
             Request.CreateResponse(HttpStatusCode.Created, modelResult);
             result[0] = "Item Created";
             result[1] = modelResult;
             Inventory item = (Inventory)modelResult;
             return(JsonConvert.SerializeObject(result));
         }
     }
     catch
     {
         result[0] = "Bad Request";
         result[1] = "Data type conversion error.";
         return(JsonConvert.SerializeObject(result));
     }
 }
        public ActionResult Create([Bind(Include = "CompanyName,Phone")] Shippers shippers)
        {
            if (ModelState.IsValid)
            {
                db.Shippers.Add(shippers);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(shippers));
        }
        public ActionResult Create([Bind(Include = "CatID,Name,Description,Picture")] Categories categories)
        {
            if (ModelState.IsValid)
            {
                db.Categories.Add(categories);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(categories));
        }
Esempio n. 4
0
        public ActionResult Create([Bind(Include = "Id,Brand,Model,Production_Year,Color,Status,Category")] Car car)
        {
            if (ModelState.IsValid)
            {
                db.Cars.Add(car);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(car));
        }
Esempio n. 5
0
        public ActionResult Create([Bind(Include = "CompanyName,ContactName,ContactTitle,Address,City,Region,PostalCode,Country,Phone,fax")] Customers customers)
        {
            if (ModelState.IsValid)
            {
                db.Customers.Add(customers);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(customers));
        }
        public ActionResult Create([Bind(Include = "TerritoryID,TerritoryDesc,RegionID")] Territories territories)
        {
            if (ModelState.IsValid)
            {
                db.Territories.Add(territories);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.RegionID = new SelectList(db.Regions, "RegionID", "RegionDesc", territories.RegionID);
            return(View(territories));
        }
Esempio n. 7
0
        public ActionResult Create([Bind(Include = "EmployeeID,LastName,FirstName,Title,Birthdate,Hiredate,Address,City,Region,PostalCode,Country,HomePhone,Extension,Photo,ReportsToID")] Employees employees)
        {
            if (ModelState.IsValid)
            {
                db.Employees.Add(employees);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ReportsToID = new SelectList(db.Employees, "EmployeeID", "LastName", employees.ReportsToID);
            return(View(employees));
        }
Esempio n. 8
0
        public ActionResult Create([Bind(Include = "Id,Name,CategoryId")] Product product)
        {
            if (ModelState.IsValid)
            {
                db.Products.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CategoryId = new SelectList(db.Categories, "Id", "Name", product.CategoryId);
            return(View(product));
        }
Esempio n. 9
0
        public ActionResult Create([Bind(Include = "Id,Name,CategoryId,ProductId")] Item item)
        {
            if (ModelState.IsValid)
            {
                db.Items.Add(item);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CategoryId = new SelectList(db.Categories, "Id", "Name", item.CategoryId);
            ViewBag.ProductId  = new SelectList(db.Products, "Id", "Name", item.ProductId);
            return(View(item));
        }
Esempio n. 10
0
        public ActionResult Create([Bind(Include = "ProductID,ProductName,UnitPrice,SupplierID,CategoryID,QuantityPerUnit,UnitsInStock,UnitsInOrder,ReorderLevel,Discontinued")] Products products)
        {
            if (ModelState.IsValid)
            {
                db.Products.Add(products);
                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 Create([Bind(Include = "ProductID,OrderID,UnitPrice,Quanity,Discount")] OrderDetails orderDetails)
        {
            if (ModelState.IsValid)
            {
                db.OrderDetails.Add(orderDetails);
                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));
        }
Esempio n. 12
0
        public ActionResult Create([Bind(Include = "OrderID,OrderDate,CustID,EmployeeID,RequiredDate,ShippedDate,ShipVia,shipAddress,ShipCity,ShipRegion,ShipPostalCode,ShipCountry")] Orders orders)
        {
            if (ModelState.IsValid)
            {
                db.Orders.Add(orders);
                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));
        }
Esempio n. 13
0
 private void btnSubmit_Click(object sender, RoutedEventArgs e)
 {
     if (gotPhoneNumber && gotFname && gotLname && gotUsername && gotPassword && gotConfirmPassword &&
         gotEmail && gotAddress && comboBoxRoles.SelectedItem != null)
     {
         InventoryDBContext inventoryDBContext = new InventoryDBContext();
         RoleRepository     roleRepository     = new RoleRepository();
         User user = new User()
         {
             Username    = tbxUsername.Text,
             Address     = tbxAddress.Text,
             Email       = tbxEmail.Text,
             IsDisabled  = false,
             Password    = tbxPassword.Password,
             PhoneNumber = long.Parse(tbxPhoneNumber.Text),
             RoleId      = roleRepository.GetRoleByName(comboBoxRoles.Text.ToString()).RoleId,
         };
         inventoryDBContext.Users.Add(user);
         inventoryDBContext.SaveChanges();
         MessageBox.Show("User created successfully!");
         this.Close();
     }
     else
     {
         MessageBox.Show("Please, Check all fields!");
     }
 }
Esempio n. 14
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"));
        }
Esempio n. 15
0
        public IHttpActionResult PostInventory(Inventory inventory)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Inventories.Add(inventory);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = inventory.Id }, inventory));
        }
Esempio n. 16
0
        public async Task <Stock> UpdateStock(Stock stock)
        {
            Stock existingStock = await _inventoryDBContext.Stocks.Where(temp => temp.StockId == stock.StockId).FirstOrDefaultAsync();

            if (existingStock != null)
            {
                existingStock.Quantity    = stock.Quantity;
                existingStock.UpdatedDate = DateTime.Now;
                _inventoryDBContext.SaveChanges();

                return(existingStock);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 17
0
        public async Task <Staff> EditStaff(Staff staff)
        {
            Staff existingStaff = await _inventoryDBContext.Staffs.Where(temp => temp.StaffId == staff.StaffId).FirstOrDefaultAsync();

            if (existingStaff != null)
            {
                existingStaff.Firstname   = staff.Firstname;
                existingStaff.Lastname    = staff.Lastname;
                existingStaff.Email       = staff.Email;
                existingStaff.Phone       = staff.Phone;
                existingStaff.Department  = staff.Department;
                existingStaff.UpdatedDate = DateTime.Now;
                _inventoryDBContext.SaveChanges();

                return(existingStaff);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 18
0
        public async Task <Product> EditProduct(Product product)
        {
            Product existingProduct = await _inventoryDBContext.Products.Where(temp => temp.ProductId == product.ProductId).FirstOrDefaultAsync();

            if (existingProduct != null)
            {
                existingProduct.ProductName = product.ProductName;
                existingProduct.Description = product.Description;
                existingProduct.SKU         = product.SKU;
                existingProduct.Price       = product.Price;
                existingProduct.IsActive    = product.IsActive;
                existingProduct.UpdatedDate = DateTime.Now;
                _inventoryDBContext.SaveChanges();

                return(existingProduct);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 19
0
        public dynamic Upload(IFormCollection form)
        {
            var context = new InventoryDBContext();

            //var products = context.Items.FromSql(" INSERT INTO \"Items\" (\"Name\", \"Location\", \"Date_Purchased\", \"Quantity\", \"Type\", \"Photo\", \"Color\", \"Company\", \"Serial\") VALUES ("+ Request.Form["itemName"] + "," +  Request.Form["location"] + "," + Request.Form["dateBought"] + "," + Request.Form["numItems"] + "," +  Request.Form["type"] + "," +  Request.Form["color"] + "," + Request.Form["company"] + "," +  Request.Form["serial"] + "," + Request.Form["selectedFile"] +";");

            try
            {
                Items  newItem = CreateNewItem(form);
                Byte[] picture = null;
                foreach (var file in form.Files)
                {
                    picture = UploadFile(file);
                }
                newItem.Photo = picture;
                var items = context.Items.Add(newItem);
                context.SaveChanges();
                return(new { Success = true, newItem.Name });
            }
            catch (Exception ex)
            {
                return(new { Success = false, ex.Message });
            }
        }
Esempio n. 20
0
        public int CreateOrder(IOrderConfig orderConfig, Order order)
        {
            if (orderConfig.IsOrderBanned)
            {
                return(0);
            }

            bool stockStatus = true;

            foreach (var product in order.Details)
            {
                if (!IsStockAvailable(product.ProductId, product.Quantity))
                {
                    stockStatus = false;
                }
            }
            if (!stockStatus)
            {
                return(0);
            }
            context.Orders.Add(order);
            context.SaveChanges();
            return(order.OrderId);
        }
Esempio n. 21
0
        private void btnSubmit_Click(object sender, RoutedEventArgs e)
        {
            Item item = new Item()
            {
                Barcode        = tbxBarcode.Text,
                BrandName      = tbxBrandName.Text,
                Name           = tbxProductName.Text,
                Description    = tbxDescription.Text,
                SellingPrice   = float.Parse(tbxSellingPrice.Text),
                Stock          = int.Parse(tbxStock.Text),
                Unit           = tbxUnit.Text + " " + comboBoxUnit.Text,
                WholeSalePrice = float.Parse(tbxWholeSalePrice.Text),
            };
            InventoryDBContext inventoryDBContext = new InventoryDBContext();

            inventoryDBContext.Items.Add(item);
            inventoryDBContext.SaveChanges();

            //clear all fields
            generalService = new GeneralService();
            generalService.TraverseVisualTree(this);

            MessageBox.Show("Product added successfully!");
        }
Esempio n. 22
0
 public ActionResult AddInfo <T>(Action <IQueryable <T> > process)
 {
     if (!FileIsValid(Request))
     {
         return(Content("Something was wrong. Please check the requirements of uploading files"));
     }
     // add new items or update existing items
     process(GetInfoFromExcel <T>(Request.Files[0]));
     try {   // update the database
         db.SaveChanges();
     } catch (DbEntityValidationException ex) {
         // Retrieve the error messages as a list of strings.
         var errorMessages = ex.EntityValidationErrors
                             .SelectMany(x => x.ValidationErrors)
                             .Select(x => x.ErrorMessage);
         // Join the list to a single string.
         var fullErrorMessage = string.Join("; ", errorMessages);
         // Combine the original exception message with the new one.
         var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage);
         // Throw a new DbEntityValidationException with the improved exception message.
         throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors);
     }
     return(RedirectToAction("Result", new { s = "Inventory was updated!" }));
 }
Esempio n. 23
0
 public void Save()
 {
     _context.SaveChanges();
 }