Exemplo n.º 1
0
        public JsonResult GetHall(int hallId)
        {
            JsonResponseModel result = new JsonResponseModel();

            try
            {
                if (hallId > 0)
                {
                    _hallLogic = new HallLogic();
                    HALL hall = _hallLogic.GetEntityBy(c => c.Id == hallId);

                    if (hall != null)
                    {
                        result.HallId          = hall.Id;
                        result.HallName        = hall.Name;
                        result.HallDescription = hall.Description;
                    }

                    result.IsError = false;
                }
                else
                {
                    result.IsError = true;
                    result.Message = "Invalid parameter";
                }
            }
            catch (Exception ex)
            {
                result.IsError = true;
                result.Message = ex.Message;
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        public IHttpActionResult PostHALL(HALL hALL)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.HALLs.Add(hALL);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (HALLExists(hALL.HallID))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = hALL.HallID }, hALL));
        }
        public IHttpActionResult PutHALL(int id, HALL hALL)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != hALL.HallID)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 4
0
        public JsonResult CreateHall(string name, string description)
        {
            JsonResponseModel result = new JsonResponseModel();

            try
            {
                if (!string.IsNullOrEmpty(name))
                {
                    _hallLogic = new HallLogic();
                    HALL existingHall = _hallLogic.GetEntitiesBy(c => c.Name.ToLower().Trim() == name.ToLower().Trim()).LastOrDefault();
                    if (existingHall == null)
                    {
                        HALL maxHall   = _hallLogic.GetAll().LastOrDefault();
                        int  maxHallId = 0;
                        if (maxHall != null)
                        {
                            maxHallId = maxHall.Id + 1;
                        }
                        else
                        {
                            maxHallId = 1;
                        }

                        existingHall = new HALL();

                        existingHall.Id          = maxHallId;
                        existingHall.Name        = name;
                        existingHall.Description = description;
                        existingHall.Active      = true;

                        _hallLogic.Create(existingHall);

                        result.IsError = false;
                        result.Message = "Operation Successful!";
                    }
                    else
                    {
                        result.IsError = true;
                        result.Message = "Hall with the same name exists.";
                    }
                }
                else
                {
                    result.IsError = true;
                    result.Message = "Invalid parameter";
                }
            }
            catch (Exception ex)
            {
                result.IsError = true;
                result.Message = ex.Message;
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        public IHttpActionResult GetHALL(int id)
        {
            HALL hALL = db.HALLs.Find(id);

            if (hALL == null)
            {
                return(NotFound());
            }

            return(Ok(hALL));
        }
        public IHttpActionResult DeleteHALL(int id)
        {
            HALL hALL = db.HALLs.Find(id);

            if (hALL == null)
            {
                return(NotFound());
            }

            db.HALLs.Remove(hALL);
            db.SaveChanges();

            return(Ok(hALL));
        }
Exemplo n.º 7
0
        public JsonResult SaveHall(int hallId, string name, string description)
        {
            JsonResponseModel result = new JsonResponseModel();

            try
            {
                if (hallId > 0 && !string.IsNullOrEmpty(name))
                {
                    _hallLogic = new HallLogic();
                    HALL hall = _hallLogic.GetEntityBy(c => c.Id == hallId);

                    HALL existingHall = _hallLogic.GetEntitiesBy(c => c.Name.ToLower().Trim() == name.ToLower().Trim() && c.Id != hallId).LastOrDefault();
                    if (existingHall == null)
                    {
                        if (hall != null)
                        {
                            hall.Name        = name;
                            hall.Description = description;

                            _hallLogic.Modify(hall);
                        }

                        result.IsError = false;
                        result.Message = "Operation Successful!";
                    }
                    else
                    {
                        result.IsError = true;
                        result.Message = "Hall with the same name exists.";
                    }
                }
                else
                {
                    result.IsError = true;
                    result.Message = "Invalid parameter";
                }
            }
            catch (Exception ex)
            {
                result.IsError = true;
                result.Message = ex.Message;
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 8
0
        private ATTENDANCE ProcessHallAttendance(HALL hall, STUDENT student)
        {
            ATTENDANCE attendance = null;

            try
            {
                AttendanceLogic attendanceLogic = new AttendanceLogic();
                EventLogic      eventLogic      = new EventLogic();

                int numberOfTimesPresent = attendanceLogic.GetEntitiesBy(s => s.EVENT.Hall_Id == hall.Id && s.Student_Id == student.Person_Id &&
                                                                         s.Attendance_Status_Id == (int)AttendanceStatuses.Present).Count();
                int numberOfLectures = eventLogic.GetEntitiesBy(s => s.Hall_Id == hall.Id && (s.Active == true || s.Active == null)).Count();
                int numberOfAbsence  = attendanceLogic.GetEntitiesBy(s => s.EVENT.Hall_Id == hall.Id && s.Student_Id == student.Person_Id &&
                                                                     s.Attendance_Status_Id == (int)AttendanceStatuses.Excused).Count();
                int numberOfLecturesHeld = numberOfLectures - numberOfAbsence;

                double eligibilityPercentage = (Convert.ToDouble(numberOfTimesPresent) / Convert.ToDouble(numberOfLecturesHeld)) * 100.0;

                attendance            = new ATTENDANCE();
                attendance.Percentage = eligibilityPercentage;

                //result.ApproximateNumberOfLectures = numberOfLecturesHeld;
                //result.EligibilityPercentage = eligibilityPercentage;
                //result.NumberOfAbsent = numberOfAbsence;
                //result.NumberOfPresent = numberOfTimesPresent;
                //result.TotalNumberOfLectures = numberOfLectures;

                if (eligibilityPercentage > 75)
                {
                    attendance.IsEligible = true;
                }
                else
                {
                    attendance.IsEligible = false;
                }
            }
            catch (Exception)
            {
                throw;
            }

            return(attendance);
        }