/* commented methods which send JSON data
         * // returns all customers
         * public ActionResult getCustomers() // JSON Collection
         * {
         *  // fill the customers collections
         *  Dal.Dal dal = new Dal.Dal();
         *  List<Customer> customersColl = dal.Customers.ToList<Customer>();
         *
         *  // Delay for Synchronous execution (10sec)
         *  //Thread.Sleep(3000);
         *
         *  return Json(customersColl, JsonRequestBehavior.AllowGet);
         * }
         *
         * // returns the Customer for entered Customor Name
         * [ActionName("getCustomerByName")]
         * public ActionResult getCustomers(Customer objCustomer) // JSON Collection
         * {
         *  // fill the customers collections
         *  Dal.Dal dal = new Dal.Dal();
         *  List<Customer> customersColl = (from c in dal.Customers
         *                                  where c.CustomerName == objCustomer.CustomerName
         *                                  select c).ToList<Customer>();
         *
         *  // Delay for Synchronous execution (10sec)
         * // Thread.Sleep(3000);
         *
         *  return Json(customersColl, JsonRequestBehavior.AllowGet);
         * }
         *
         *
         * // return the Customer for entered Customor Name
         * // returns View - SearchCustomer
         * public ActionResult SearchCustomer()
         * {
         *  // View Model object
         *  CustomerViewModel obj = new CustomerViewModel();
         *
         *  // fill the customers collections
         *  Dal.Dal dal = new Dal.Dal();
         *  // to fill all customers
         *  // List<Customer> customersColl = dal.Customers.ToList<Customer>();
         *
         *  string str = Request.Form["txtCustomerName"].ToString();
         *
         *  // to filter customers with conditions
         *  List<Customer> customersColl
         *      = (from x in dal.Customers
         *         where x.CustomerName == str
         *         select x).ToList<Customer>();
         *  obj.customers = customersColl;
         *
         *  return View("SearchCustomer", obj);
         * }
         *
         */

        public ActionResult Submit(Customer obj) // validation runs
        {
            //// no need - as JSON object is being passed from front end
            //// manual binding of object with form elements
            //Customer obj = new Customer();
            //obj.CustomerName = Request.Form["customer.CustomerName"];
            //obj.CustomerCode = Request.Form["customer.CustomerCode"];
            //// no need - end

            if (ModelState.IsValid)
            {
                // insert the Customer object to database
                // EF DAL
                Dal.Dal Dal = new Dal.Dal();
                Dal.Customers.Add(obj); // in memory
                Dal.SaveChanges();      // physical commit

                //return View("Customer", obj);
            }

            // fill the customers collections
            Dal.Dal         dal           = new Dal.Dal();
            List <Customer> customersColl = dal.Customers.ToList <Customer>();

            //return View("EnterCustomer",vm);    // removed as JSON will be sent
            return(Json(customersColl, JsonRequestBehavior.AllowGet));
        }
        // Select
        public List <Customer> Get()
        {
            // Read the query string
            var allUrlKeyValues = ControllerContext.Request.GetQueryNameValuePairs();

            string customerCode = allUrlKeyValues.SingleOrDefault(x => x.Key == "CustomerCode").Value;
            string customerName = allUrlKeyValues.SingleOrDefault(x => x.Key == "CustomerName").Value;

            // fill the customers collections
            Dal.Dal         dal           = new Dal.Dal();
            List <Customer> customersColl = new List <Customer>();

            if (customerName != null)
            {
                // Select the record using LINQ (used in Serch Customer Screen)
                // fill the customers collections
                customersColl = (from c in dal.Customers
                                 where c.CustomerName == customerName
                                 select c).ToList <Customer>();
            }

            else if (customerCode != null)
            {
                customersColl = (from c in dal.Customers
                                 where c.CustomerCode == customerCode
                                 select c).ToList <Customer>();
            }

            else
            {
                customersColl = dal.Customers.ToList <Customer>();
            }

            return(customersColl);
        }
Ejemplo n.º 3
0
        public List <Book> Get() // All the record
        {
            var allUrlKeyValues = ControllerContext.Request.GetQueryNameValuePairs();

            string bookGenre = allUrlKeyValues.
                               SingleOrDefault(x => x.Key == "bookGenre").Value;
            string bookName = allUrlKeyValues.
                              SingleOrDefault(x => x.Key == "bookName").Value;

            Dal.Dal     dal       = new Dal.Dal();
            List <Book> booksList = new List <Book>();

            if (bookName != null)
            {
                booksList = (from t in dal.Books
                             where t.bookName == bookName
                             select t).ToList <Book>();
            }
            else if (bookGenre != null)
            {
                booksList = (from t in dal.Books
                             where t.bookGenre == bookGenre
                             select t).ToList <Book>();
            }
            else
            {
                booksList = dal.Books.ToList <Book>();
            }

            return(booksList);
        }
        // Insert
        public /*List<Customer>*/ Object Post(Customer objCustomer)  // Object - to avoid typecasting error (Error to Customers)
        {
            if (ModelState.IsValid)
            {
                // insert the Customer object to database
                // EF DAL
                Dal.Dal Dal = new Dal.Dal();
                Dal.Customers.Add(objCustomer); // in memory
                Dal.SaveChanges();              // physical commit
            }
            else  // get all the errors in ModelState and put it in Error collection
            {
                var Err = new Error();
                Err.Errors = new List <string>(); // to avoid null reference in Err.Errors.Add
                foreach (var modelState in ModelState)
                {
                    foreach (var error in modelState.Value.Errors)
                    {
                        Err.Errors.Add(error.ErrorMessage);
                    }
                }
                objClientData.isValid = false;
                objClientData.data    = Err;
                return(objClientData);
            }

            // fill the customers collections
            Dal.Dal         dal           = new Dal.Dal();
            List <Customer> customersColl = dal.Customers.ToList <Customer>();

            //return customersColl; // WebAPI will decide the content type on its own (HTML, JSON, JPEG...)
            objClientData.isValid = true;
            objClientData.data    = customersColl;
            return(objClientData);  // WebAPI will decide the content type on its own (HTML, JSON, JPEG...)
        }
Ejemplo n.º 5
0
        public ActionResult SubmitLogin(Assistant a)
        {
            if (ModelState.IsValid)
            {
                Dal.Dal dal  = new Dal.Dal();
                string  name = a.AFirstName.ToString();
                string  id   = a.AIDNumber.ToString();
                Session["AFirstName"] = a.AFirstName.ToString();
                Session["AIDNumber"]  = a.AIDNumber.ToString();
                List <Assistant> tid   = (from x in dal.Assistant where x.AIDNumber == id select x).ToList();
                List <Assistant> tname = (from x in dal.Assistant where x.AFirstName == name select x).ToList();

                if (tid.Count == 0 || tname.Count == 0)
                {
                    ViewData["errormessage"] = "The Name or IDNumber is not valid";
                    return(View("Login", a));
                }
                if (tid[0].AIDNumber == id && tname[0].AFirstName == name)
                {
                    return(View("viewAssistant"));
                }
                else
                {
                    ViewData["errormessage"] = "The Name or IDNumber is not valid";
                    return(View("Login", a));
                    //return View("Index");
                }
            }
            else
            {
                return(View("Index"));
            }
        }
Ejemplo n.º 6
0
        //SubmitLogin
        public ActionResult SubmitLogin(Teacher t)
        {
            if (ModelState.IsValid)
            {
                Dal.Dal dal  = new Dal.Dal();
                string  name = t.FirstName.ToString();
                string  id   = t.TeacherId.ToString();
                Session["IDValue"]   = t.FirstName.ToString();
                Session["PassValue"] = t.TeacherId.ToString();
                List <Teacher> tid   = (from x in dal.Teacher where x.TeacherId == id select x).ToList();
                List <Teacher> tname = (from x in dal.Teacher where x.FirstName == name select x).ToList();

                if (tid.Count == 0 || tname.Count == 0)
                {
                    ViewData["errormessage"] = "The Name or TeacherId is not valid";
                    return(View("Login", t));
                }
                if (tid[0].TeacherId == id && tname[0].FirstName == name)
                {
                    return(View("viewTeacher"));
                }
                else
                {
                    ViewData["errormessage"] = "The Name or IDNumber is not valid";
                    return(View("Login", t));
                    //return View("Index");
                }
            }
            else
            {
                return(View("Index"));
            }
        }
Ejemplo n.º 7
0
        public List <Book> Put(Book obj)
        {
            Dal.Dal dal        = new Dal.Dal();
            Book    custupdate = (from temp in dal.Books
                                  where temp.bookGenre == obj.bookGenre
                                  select temp).ToList <Book>()[0];

            custupdate.bookCost = obj.bookCost;
            custupdate.bookName = obj.bookName;
            List <Book> booksList = dal.Books.ToList <Book>();

            return(booksList);
        }
Ejemplo n.º 8
0
        public List <Book> Post(Book obj)
        {
            if (ModelState.IsValid)
            {
                Dal.Dal Dal = new Dal.Dal();
                Dal.Books.Add(obj);
                Dal.SaveChanges();
            }

            Dal.Dal     dal       = new Dal.Dal();
            List <Book> booksList = dal.Books.ToList <Book>();

            return(booksList);
        }
Ejemplo n.º 9
0
        public List <Book> Delete(Book obj)
        {
            // Select the record
            Dal.Dal Dal        = new Dal.Dal();
            Book    custdelete = (from temp in Dal.Books
                                  where temp.bookGenre == obj.bookGenre
                                  select temp).ToList <Book>()[0];

            // Remove
            Dal.Books.Remove(custdelete);
            Dal.SaveChanges();
            List <Book> booksList = Dal.Books.ToList <Book>();

            return(booksList);
        }
        // Delete
        public List <Customer> Delete(Customer objCustomer)
        {
            // Select the record using LINQ
            Dal.Dal  objDal     = new Dal.Dal();
            Customer custDelete = (from c in objDal.Customers
                                   where c.CustomerCode == objCustomer.CustomerCode
                                   select c).ToList <Customer>()[0];

            objDal.Customers.Remove(custDelete);
            objDal.SaveChanges();

            List <Customer> customerColl = objDal.Customers.ToList <Customer>();

            return(customerColl);
        }
        /* // Start - commented as it will be handled in one Get method
         * // Select (used in Serch Customer Screen
         * public List<Customer> Get(string CustomerName)  // parameter name should match the query string parameters
         * {
         *  // fill the customers collections
         *  Dal.Dal dal = new Dal.Dal();
         *  List<Customer> customersColl = (from c in dal.Customers
         *                                  where c.CustomerName == CustomerName
         *                                  select c).ToList<Customer>();
         *  return customersColl;
         * }
         */// End - commented as it will be handled in one Get method

        // Update
        public List <Customer> Put(Customer objCustomer)
        {
            // Select the record using LINQ
            Dal.Dal  objDal     = new Dal.Dal();
            Customer custUpdate = (from c in objDal.Customers
                                   where c.CustomerCode == objCustomer.CustomerCode
                                   select c).ToList <Customer>()[0];

            // Update the record
            custUpdate.CustomerName   = objCustomer.CustomerName;
            custUpdate.CustomerAmount = objCustomer.CustomerAmount;

            List <Customer> customerColl = objDal.Customers.ToList <Customer>();

            return(customerColl);
        }
Ejemplo n.º 12
0
        public ActionResult Validate()
        {
            // Forms Authentication
            string username = Request.Form["UserName"].Trim(); // to remove leading or trailing blank spaces
            string password = Request.Form["Password"].Trim();

            Dal.Dal dal = new Dal.Dal();

            List <User> users = (from u in dal.Users
                                 where (u.UserName == username) &&
                                 (u.Password == password)
                                 select u
                                 ).ToList <User>();

            if (users.Count == 1)
            {
                FormsAuthentication.SetAuthCookie("Cookie", true);
                return(View("GotoHome"));
            }
            else
            {
                return(View("Login"));
            }
        }