public IEnumerable <student> GetStud()
 {
     using (StudentdbEntities studentdbEntities = new StudentdbEntities())
     {
         lstStudent = studentdbEntities.students.ToList();
         return(lstStudent);
     }
 }
Exemple #2
0
        public ActionResult Edit(employee emp)
        {
            StudentdbEntities db = new StudentdbEntities();

            db.Entry(emp).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemple #3
0
        public ActionResult Create(employee emp)
        {
            StudentdbEntities db = new StudentdbEntities();

            db.employees.Add(emp);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemple #4
0
        public ActionResult Index()
        {
            List <employee> empList = new List <employee>();

            using (StudentdbEntities studentdbEntities = new StudentdbEntities())
            {
                empList = studentdbEntities.employees.ToList();
            }

            //ViewBag.Title = "Home Page";

            return(View(empList));
        }
Exemple #5
0
        public ActionResult Delete(int?id)
        {
            StudentdbEntities db = new StudentdbEntities();

            if (id != null)
            {
                employee emp = db.employees.Find(id);
                db.employees.Remove(emp);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View());
        }
Exemple #6
0
        public ActionResult Index()
        {
            if (Session["UserId"] != null)
            {
                using (StudentdbEntities studentdbEntities = new StudentdbEntities())
                {
                    empList = studentdbEntities.employees.ToList();
                    return(View(empList));
                }
            }
            else
            {
                return(RedirectToAction("Login", "Login"));
            }

            //ViewBag.Title = "Home Page";
        }
Exemple #7
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(RedirectToAction("Index"));
            }

            StudentdbEntities db = new StudentdbEntities();

            employee emp = db.employees.Where(x => x.Id == id).Single();

            if (emp == null)
            {
                return(HttpNotFound());
            }

            return(View(emp));


            //return RedirectToAction("Index");
        }
Exemple #8
0
        public ActionResult Login(user usr)
        {
            List <user>       lst = new List <user>();
            StudentdbEntities db  = new StudentdbEntities();

            lst             = dbLayer.Login_User(usr);
            TempData["msg"] = "Login Successs";

            //var ussr = db.users.Single(u => u.Name == usr.Name && u.passwd == usr.passwd);
            if (lst != null && lst.Count > 0)
            {
                FormsAuthentication.SetAuthCookie(Request.Form["UserId"], true);
                Session["UserId"]   = lst.FirstOrDefault().UserId;
                Session["Username"] = lst.FirstOrDefault().Name;
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                TempData["msg"] = "Incorrect Username or Password";
                return(View("Login"));
            }
        }
Exemple #9
0
        public override void OnAuthorization(HttpActionContext actionContext)
        {
            base.OnAuthorization(actionContext);


            if (actionContext.Request.Headers.Authorization == null)
            {
                HttpResponseMessage httpResponse = new HttpResponseMessage(HttpStatusCode.Forbidden);
                httpResponse.Content = new StringContent("Authorization Data is missing!!!");
                //httpResponse.ReasonPhrase = "No Authorization!!";
                actionContext.Response = httpResponse;
            }
            else
            {
                String   encodedData = actionContext.Request.Headers.Authorization.Parameter;
                String   decodeData  = Encoding.UTF8.GetString(Convert.FromBase64String(encodedData));
                String[] userdata    = decodeData.Split(':');

                //int uid = Convert.ToInt32(userdata[0]);
                String uname = userdata[0];
                String pass  = userdata[1];

                StudentdbEntities db = new StudentdbEntities();

                User u1 = db.Users.Where(u => u.u_name == uname && u.u_pass.Equals(pass)).FirstOrDefault();
                if (u1 != null)
                {
                    Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity(u1.u_name), null);
                }
                else
                {
                    HttpResponseMessage httpResponse = new HttpResponseMessage(HttpStatusCode.Unauthorized);
                    httpResponse.Content      = new StringContent("Authorization Data is invalid !!!");
                    httpResponse.ReasonPhrase = "No Authorization!!";
                    actionContext.Response    = httpResponse;
                }
            }
        }
        // GET: Order
        public ActionResult Orders()
        {
            // StudentdbEntities db = new StudentdbEntities();
            //var empOrders = db.employees.Join(db.Ordertbls,
            //     e => e.Id, o => o.EmployeeId, (e, o) => e);
            // //return View();
            // return View(ViewBag.orderDetails=empOrders);
            StudentdbEntities db        = new StudentdbEntities();
            List <OrderVM>    lstOrders = new List <OrderVM>();

            lstOrders = (from emp in db.employees
                         join od in db.Ordertbls on emp.Id equals od.EmployeeId
                         join it in db.Items on od.ItemId equals it.Id
                         orderby od.Id
                         select new OrderVM
            {
                Id = od.Id,
                EmpName = emp.EmpName,
                ItemName = it.ItemName,
                Price = it.Price,
                Descr = od.Descr
            }).ToList();
            return(View(lstOrders));
        }
        public ActionResult OrdersLeftJoin()
        {
            StudentdbEntities db        = new StudentdbEntities();
            List <OrderVM>    lstOrders = new List <OrderVM>();

            //Working
            lstOrders = (from it in db.Items
                         join od in db.Ordertbls on it.Id equals od.ItemId
                         //orderby od.Id
                         into dep
                         from dept in dep.DefaultIfEmpty()
                         select new OrderVM
            {
                Id = (int?)it.Id,
                // Id = dept.Id,
                ItemName = it.ItemName,
                Price = it.Price,
                Descr = dept.Descr
            }).ToList();


            //lstOrders = (from it in db.Items
            //             join od in db.Ordertbls on it.Id equals od.ItemId
            //             //orderby od.Id

            //             select new OrderVM
            //             {
            //                 Id = od.Id,
            //                 ItemName = it.ItemName,
            //                 Price = it.Price,
            //                 Descr = od.Descr
            //             }).ToList();


            //var query = from e in db.employees
            //            join od in db.Ordertbls on e.Id equals od.EmployeeId into t
            //            from nt in t.DefaultIfEmpty()
            //            orderby e.Id

            //            select new
            //            {
            //                e.Id,
            //                e.EmpName,
            //                nt.Descr
            //            };



            // StudentdbEntities db = new StudentdbEntities();
            //lstOrders = (from emp in db.employees
            //             join od in db.Ordertbls on emp.Id equals od.EmployeeId
            //             join it in db.Items on od.ItemId equals it.Id
            //             into dep
            //             from dept in dep.DefaultIfEmpty()
            //             select new OrderVM
            //             {
            //                 Id = (int?)dept.Id,
            //                 EmpName = emp.EmpName,
            //                 ItemName = dept.ItemName,
            //                 Price = dept.Price,
            //                 Descr = od.Descr
            //             }).ToList();

            //var lst = (from emp in db.employees
            //           join od in db.Ordertbls on emp.Id equals od.EmployeeId
            //           join it in db.Items on od.ItemId equals it.Id
            //           into dep
            //           from dept in dep.DefaultIfEmpty()
            //           select emp
            //          ).ToList();


            return(View(lstOrders));
        }