Example #1
0
        public ActionResult Class()
        {
            try
            {
                using (Test2Entities db = new Test2Entities())
                {
                    var oClass = (from c in db.@class
                                  join s in db.subject
                                  on c.id_subject equals s.id
                                  join p in db.professor
                                  on c.id_professor equals p.id
                                  join d in db.day
                                  on c.id_day equals d.id
                                  select new Classroom()
                    {
                        Subject = s.name,
                        ProfessorName = p.name,
                        ProfessorSurname = p.surname,
                        Day = d.name,
                        StartTime = c.start_time.ToString(),
                        EndTime = c.end_time.ToString(),
                        Capacity = c.capacity
                    });

                    return(View(oClass.ToList()));
                }
            }
            catch (Exception e)
            {
                ViewBag.Error = e.Message;
                return(RedirectToAction("Login", "Access"));
            }
        }
        public HttpResponseMessage PutEmployee(int id, [FromBody] Employee emp)
        {
            try
            {
                using (Test2Entities _db = new Test2Entities())
                {
                    var data = _db.Employees.Where(e => e.id == id).SingleOrDefault();

                    if (data != null)
                    {
                        data.id     = emp.id;
                        data.Name   = emp.Name;
                        data.Salary = emp.Salary;
                        data.Gender = emp.Gender;
                        data.City   = emp.City;

                        _db.SaveChanges();
                        return(Request.CreateResponse(HttpStatusCode.OK, data));
                    }
                    else
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Employee with id " + id.ToString() + " is not found"));
                    }
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
Example #3
0
 public IEnumerable <Employee> GetEmployees()
 {
     using (Test2Entities _db = new Test2Entities())
     {
         return(_db.Employees.ToList());
     }
 }
Example #4
0
 public static bool Login(string username, string password)
 {
     using (Test2Entities _db = new Test2Entities())
     {
         return(_db.Users.Any(u => u.Username.Equals(username, StringComparison.OrdinalIgnoreCase) && u.Password == password));
     }
 }
        public HttpResponseMessage GetEmployee(int id)
        {
            using (Test2Entities _db = new Test2Entities())
            {
                var data = _db.Employees.FirstOrDefault(e => e.id == id);

                if (data != null)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, data));
                }
                else
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Employee with id    " + id + " is not found"));
                }
            }
        }
        public HttpResponseMessage Post([FromBody] Employee emp)
        {
            try
            {
                using (Test2Entities _db = new Test2Entities())
                {
                    _db.Employees.Add(emp);
                    _db.SaveChanges();

                    var message = Request.CreateResponse(HttpStatusCode.Created, emp);
                    message.Headers.Location = new Uri(Request.RequestUri + emp.id.ToString());
                    return(message);
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
Example #7
0
        public ActionResult Login(string User, string Pass)
        {
            Session["User"] = null;

            int userRole;
            int adminRole = 1;

            try
            {
                using (Test2Entities db = new Test2Entities())
                {
                    var oUser = (from d in db.user
                                 where d.dni == User.Trim() && d.file_number.ToString() == Pass
                                 select d).FirstOrDefault();

                    if (oUser == null)
                    {
                        ViewBag.Error = "Usuario o password invalido";
                        return(View());
                    }

                    userRole = oUser.id_role;

                    Session["User"] = oUser;
                }

                if (userRole == adminRole)
                {
                    return(RedirectToAction("Index", "Admin"));
                }
                else
                {
                    return(RedirectToAction("Class", "Student"));
                }
            }
            catch (Exception e)
            {
                ViewBag.Error = e.Message;
                return(View());
            }
        }
        public HttpResponseMessage GetEmployees(string gender = "All")
        {
            string username = Thread.CurrentPrincipal.Identity.Name;

            using (Test2Entities _db = new Test2Entities())
            {
                switch (username.ToLower())
                {
                case "all":
                    return(Request.CreateResponse(HttpStatusCode.OK, _db.Employees.ToList()));

                case "male":
                    return(Request.CreateResponse(HttpStatusCode.OK, _db.Employees.Where(e => e.Gender.ToLower() == "male").ToList()));

                case "female":
                    return(Request.CreateResponse(HttpStatusCode.OK, _db.Employees.Where(e => e.Gender.ToLower() == "female").ToList()));

                default:
                    return(Request.CreateResponse(HttpStatusCode.BadGateway, "Value of Gender must be All, Male or Female. " + gender + " is invalid"));
                }
            }
        }
 public HttpResponseMessage DeleteEmployee(int id)
 {
     try
     {
         using (Test2Entities _db = new Test2Entities())
         {
             var data = _db.Employees.FirstOrDefault(e => e.id == id);
             if (data != null)
             {
                 _db.Employees.Remove(data);
                 _db.SaveChanges();
                 return(Request.CreateResponse(HttpStatusCode.OK, data));
             }
             else
             {
                 return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Employee with id " + id.ToString() + " is not found"));
             }
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
 }