public ActionResult Create(FormCollection collection)
        {
            try
            {
                var name     = collection.Get("Name");
                var price    = double.Parse(collection.Get("Price"));
                var quantity = int.Parse(collection.Get("Quantity"));

                var newProduct = new Product();
                newProduct.Id       = 1;
                newProduct.Name     = name;
                newProduct.Price    = price;
                newProduct.Quantity = quantity;

                // Save
                assignmentEntities.Products.Add(newProduct);
                assignmentEntities.SaveChanges();

                return(RedirectToAction("Index"));
            }
            catch (DbUpdateException ex)
            {
                Console.WriteLine(ex.Message);
                return(View());
            }
        }
        public ActionResult Add(view_Expense UpdatedExpenses)
        {
            AssignmentEntities db       = new AssignmentEntities();
            Expense            expenses = new Expense();

            expenses.Description = UpdatedExpenses.Description;
            expenses.Date        = UpdatedExpenses.Date;
            expenses.Amount      = UpdatedExpenses.Amount;

            Category category = db.Categories.Where(x => x.CategoryName == UpdatedExpenses.CategoryName).FirstOrDefault();

            if (category == null)
            {
                Category new_category = new Category();
                new_category.CategoryName = UpdatedExpenses.CategoryName;
                db.Categories.Add(new_category);
                db.SaveChanges();
                category = db.Categories.Where(x => x.CategoryName == UpdatedExpenses.CategoryName).FirstOrDefault();
            }

            expenses.CategoryId = category.CategoryId;
            db.Expenses.Add(expenses);
            db.SaveChanges();

            db.Dispose();
            return(Redirect("Index"));
        }
        public IHttpActionResult PutCustomer(string id, Customer customer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != customer.Id)
            {
                return(BadRequest());
            }

            db.Entry(customer).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CustomerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 4
0
        public ActionResult Create([Bind(Include = "Id,Venue,AvailableDate,Address")] Karaoke karaoke)
        {
            if (ModelState.IsValid)
            {
                db.Karaokes.Add(karaoke);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(karaoke));
        }
        public ActionResult Create([Bind(Include = "Id,Name,Quantity,Price")] Product product)
        {
            if (ModelState.IsValid)
            {
                db.Products.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(product));
        }
Ejemplo n.º 6
0
        public ActionResult Create([Bind(Include = "Id,EmployeeName,Age,MaritialStatus,Salary,Address")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                db.Employees.Add(employee);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(employee));
        }
Ejemplo n.º 7
0
        public ActionResult Create([Bind(Include = "Id,Latitude,Longitude,KaraokeId")] Location location)
        {
            if (ModelState.IsValid)
            {
                db.Locations.Add(location);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.KaraokeId = new SelectList(db.Karaokes, "Id", "Venue", location.KaraokeId);
            return(View(location));
        }
Ejemplo n.º 8
0
        public ActionResult Create([Bind(Include = "CategoryId,CategoryName,SeqNo,ParentCategoryId")] Category category)
        {
            if (ModelState.IsValid)
            {
                db.Categories.Add(category);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ParentCategoryId = new SelectList(db.Categories, "CategoryId", "CategoryName", category.ParentCategoryId);
            return(View(category));
        }
Ejemplo n.º 9
0
        public ActionResult Create([Bind(Include = "Date,Time,Until,Food_And_Drinks,Apply_For_Party,Leave_Message,Rate,CustomerId,KaraokeId")] Booking booking)
        {
            if (ModelState.IsValid)
            {
                db.Bookings.Add(booking);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.KaraokeId = new SelectList(db.Karaokes, "Id", "Venue", booking.KaraokeId);
            return(View(booking));
        }
Ejemplo n.º 10
0
        public ActionResult Create([Bind(Include = "ProductId,ProductName,PrimaryCategoryId,ProductDescription,Active,ProductPrice")] Product product)
        {
            if (ModelState.IsValid)
            {
                db.Products.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.PrimaryCategoryId = new SelectList(db.Categories, "CategoryId", "CategoryName", product.PrimaryCategoryId);
            return(View(product));
        }
Ejemplo n.º 11
0
        public ActionResult Add(Category categery)
        {
            AssignmentEntities db = new AssignmentEntities();

            db.Categories.Add(categery);
            db.SaveChanges();
            db.Dispose();
            return(Redirect("Index"));
        }
        public ActionResult Remove(view_Expense UpdatedExpenses)
        {
            AssignmentEntities db       = new AssignmentEntities();
            Expense            expences = db.Expenses.Where(x => x.ExpenseId == UpdatedExpenses.ExpenseId).FirstOrDefault();

            db.Expenses.Remove(expences);
            db.SaveChanges();
            db.Dispose();
            return(Redirect("Index"));
        }
Ejemplo n.º 13
0
        public ActionResult Remove(Category categoryEdited)
        {
            AssignmentEntities db       = new AssignmentEntities();
            Category           category = db.Categories.Where(x => x.CategoryId == categoryEdited.CategoryId).FirstOrDefault();

            db.Categories.Remove(category);
            db.SaveChanges();
            db.Dispose();
            return(Redirect("Index"));
        }