Exemple #1
0
        public ActionResult CreatePracticeAttendance(PracticeAttendanceModel model)
        {
            if (ModelState.IsValid)
            {
                var user = Session["Users"] as Users;
                PracticeAttended practice = new PracticeAttended
                {
                    PracticeID = model.PracticeID,
                    UserID     = model.UserID,
                    Attended   = model.Attended
                };


                List <PracticeAttended> check = attendance.getPracticeAttendaned(user.TeamID);
                bool duplicateEntry           = check.Exists(m => m.UserID == model.UserID && m.PracticeID == model.PracticeID);
                if (duplicateEntry)
                {
                    ViewBag.Message = "User Already has been entered for this practice";
                    return(View(model));
                }
                else
                {
                    attendance.CreatePracticeAttendance(practice);
                }

                //check if insert added
                List <PracticeAttended> checkAgain = attendance.getPracticeAttendaned(user.TeamID);
                bool verify = checkAgain.Exists(m => m.UserID == model.UserID && m.PracticeID == model.PracticeID);

                if (verify)
                {
                    ViewBag.Message = "Attendance Added";
                }
                else
                {
                    ViewBag.Message = "Creation Failed";
                }
            }
            else
            {
                ViewBag.Message = "Model State is not Valid";
                return(View(model));
            }

            return(View(model));
        }
        public ActionResult TwoLevelPractice(PracticeModel practice)
        {
            if (ModelState.IsValid)
            {
                if (practice.PracticeType == "")
                {
                    ViewBag.Message = "Cannot leave practice blank";
                    return(View(practice));
                }
                if (practice.StartTime < DateTime.Now)
                {
                    ViewBag.Message = "Start Time cannot be earlier than todays date";
                    return(View(practice));
                }
                else if (practice.EndTime < DateTime.Now)
                {
                    ViewBag.Message = "End Time Cannot be  earlier than todays date";
                    return(View(practice));
                }
                else if (practice.StartTime > practice.EndTime)
                {
                    ViewBag.Message = "Start Time Cannot be  later than End Time";
                    return(View(practice));
                }
                else if (practice.StartTime == DateTime.MinValue || practice.EndTime == DateTime.MinValue)
                {
                    ViewBag.Message = "Cannot be the beggining of time";
                    return(View(practice));
                }
                var              users          = Session["Users"] as Users;
                Practice         createPractice = new Practice();
                PracticeAttended absent         = new PracticeAttended();

                createPractice.PracticeType = practice.PracticeType;
                createPractice.StartTime    = practice.StartTime;
                createPractice.EndTime      = practice.EndTime;
                absent.UserID         = practice.UserID;
                absent.Attended       = practice.Check;
                createPractice.TeamID = users.TeamID;



                practiceBLL.CreatePractice(createPractice);
                List <Practice> check = practiceBLL.GetPractice();
                check.Reverse();
                Practice checkinsert = check.Find(m => m.PracticeType == createPractice.PracticeType && m.StartTime == createPractice.StartTime && m.EndTime == createPractice.EndTime);
                absent.PracticeID = checkinsert.PracticeID;

                attendance.CreatePracticeAttendance(absent);

                bool insert      = check.Exists(m => m.PracticeType == practice.PracticeType);
                bool checkInsert = attendance.getPracticeAttendaned(users.TeamID).Exists(m => m.PracticeID == check[0].PracticeID);

                if (insert && checkInsert)
                {
                    ViewBag.Message = "Practice and Attendance Created";
                }
                else if (insert && checkInsert == false)
                {
                    ViewBag.Message = "Only Practice Added";
                }
                else if (insert == false && checkInsert == false)
                {
                    ViewBag.Message = "No Insert Made";
                }
                else
                {
                }
            }
            else
            {
                ViewBag.Message = "Invalid Entry";
            }
            return(View(practice));
        }