public IHttpActionResult PutPersonInformation(int id, PersonInformation personInformation)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != personInformation.PersonId)
            {
                return BadRequest();
            }

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

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

            return StatusCode(HttpStatusCode.NoContent);
        }
Пример #2
0
        public ActionResult Create([Bind(Include = "ClassID,ClassName")] tblClass tblClass)
        {
            if (ModelState.IsValid)
            {
                tblClass.ClassActive = true;

                tblClass.ReportingDatetime = DateTime.Now;
                db.tblClasses.Add(tblClass);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(tblClass));
        }
Пример #3
0
        public ActionResult Create([Bind(Include = "SupportID,SupportNumber,SupportEmail,SupportAddress,SupportPerson,ReportingDateTime,SupportActive")] tblSupport tblSupport)
        {
            if (ModelState.IsValid)
            {
                tblSupport.SupportActive = true;

                tblSupport.ReportingDateTime = DateTime.Now;
                db.tblSupports.Add(tblSupport);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(tblSupport));
        }
Пример #4
0
        public ActionResult Create([Bind(Include = "FAQID,FAQQuestion,FAQAnswer,FAQDateTime,FAQActive")] tblFAQ tblFAQ)
        {
            if (ModelState.IsValid)
            {
                tblFAQ.FAQActive   = true;
                tblFAQ.FAQDateTime = DateTime.Now;

                db.tblFAQs.Add(tblFAQ);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(tblFAQ));
        }
Пример #5
0
        public ActionResult Create([Bind(Include = "SectionID,SectionName,ReportingDateTime,ClassID")] tblSection tblSection)
        {
            if (ModelState.IsValid)
            {
                tblSection.SectionActive = true;

                tblSection.ReportingDateTime = DateTime.Now;
                db.tblSections.Add(tblSection);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ClassID = new SelectList(db.tblClasses, "ClassID", "ClassName", tblSection.ClassID);
            return(View(tblSection));
        }
Пример #6
0
        public ActionResult Edit([Bind(Include = "UserID,StudentNo,UserRegStatus,UserRequestDate,UserReqRejectReason")] tblUser user)
        {
            if (ModelState.IsValid)
            {
                // Setting active property true.
                user.UserActive = true;

                // Setting typeID to 2 (Student)
                user.UserTypeID = 2;

                db.Entry(user).State = EntityState.Modified;
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            return(View(user));
        }
Пример #7
0
 public bool CollectAnswers(SurveyVM survey)
 {
     using (SurveyDBEntities context = new SurveyDBEntities())
     {
         using (var dbTransaction = context.Database.BeginTransaction())
         {
             try
             {
                 SurveyResponse response = context.SurveyResponses.Create();
                 response.SurveyID      = survey.SurveyID;
                 response.Company       = this.ContactInfo.Company;
                 response.FullName      = this.ContactInfo.FullName;
                 response.Email         = this.ContactInfo.Email;
                 response.Completed     = true;
                 response.LastUpdatedOn = DateTime.Now;
                 context.SurveyResponses.Add(response);
                 context.SaveChanges();
                 int i = 0;
                 foreach (Subject subject in survey.Subjects)
                 {
                     foreach (Question question in subject.Questions)
                     {
                         Answer         answer         = this.Answers[i++];
                         ResponseAnswer responseAnswer = context.ResponseAnswers.Create();
                         responseAnswer.ResponseID     = response.ResponseID;
                         responseAnswer.QuestionID     = question.QuestionID;
                         responseAnswer.SelectedAnswer = (int)answer.SelectedAnswer;
                         responseAnswer.AnswerText     = answer.AnswerText;
                         context.ResponseAnswers.Add(responseAnswer);
                     }
                 }
                 context.SaveChanges();
                 dbTransaction.Commit();
                 return(true);
             }
             catch (Exception ex)
             {
                 dbTransaction.Rollback();
                 //LogHelper.Error(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "Saving to database Error", ex);
                 return(false);
             }
         }
     }
 }
Пример #8
0
        public ActionResult Create([Bind(Include = "SurveyID,SurveyTitle,SurveyDescription,UserTypeID,SurveyConducts,SurveyActive")] tblSurvey tblSurvey, string surveyDueDate)
        {
            if (ModelState.IsValid)
            {
                // Setting all values which do not require user input to their default values
                #region
                tblSurvey.SurveyConducts          = 0;
                tblSurvey.SurveyActive            = true;
                tblSurvey.SurveyReportingDateTime = DateTime.Today.ToShortDateString();

                #endregion

                tblSurvey.SurveyDueDate = surveyDueDate;

                db.tblSurveys.Add(tblSurvey);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(tblSurvey));
        }
Пример #9
0
        public ActionResult SelectWinner([Bind(Include = "CompWinID,FirstWinner,SecondWinner,ThirdWinner")] tblCompWinner winner)
        {
            tblCompParticipant comp = db.tblCompParticipants.Find(winner.FirstWinner);
            int compID = comp.CompID;

            if (ModelState.IsValid)
            {
                int count = db.tblCompWinners.Where(t => t.tblCompParticipant.CompID == compID).Count();

                if (count == 0)
                {
                    if ((winner.FirstWinner != winner.SecondWinner) &&
                        (winner.FirstWinner != winner.ThirdWinner) &&
                        (winner.SecondWinner != winner.ThirdWinner))
                    {
                        db.tblCompWinners.Add(winner);
                        db.SaveChanges();

                        // Take user to index right after submission is done.
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        // Show some error that the three dropdowns cannot be the same.
                    }
                }
                else
                {
                    // Show some error that there are already winners for this competition
                }
            }

            ViewBag.FirstWinner  = new SelectList(db.tblCompParticipants.Where(x => x.CompID == compID), "CompParticID", "CompParticName");
            ViewBag.SecondWinner = new SelectList(db.tblCompParticipants.Where(x => x.CompID == compID), "CompParticID", "CompParticName");
            ViewBag.ThirdWinner  = new SelectList(db.tblCompParticipants.Where(x => x.CompID == compID), "CompParticID", "CompParticName");

            return(View(winner));
        }
Пример #10
0
        public ActionResult Create([Bind(Include = "StudentName,StudentEmail,SectionID,StudentGender")] tblStudent tblStudent)
        {
            if (ModelState.IsValid)
            {
                // If sectionID value is 0 (no selection), return without doing anything.
                if (tblStudent.SectionID == 0)
                {
                    ViewBag.ClassID   = new SelectList(db.tblClasses, "ClassID", "ClassName");
                    ViewBag.SectionID = new SelectList(db.tblSections, "SectionID", "SectionName", tblStudent.SectionID);
                    ViewBag.StudentID = new SelectList(db.tblUsers, "UserID", "UserName", tblStudent.StudentID);

                    return(JavaScript("Error: Select a section!"));
                    //return View(tblStudent);
                }

                // Setting Active to true whenever a new Student is created. It is false only when a user is deleted.
                tblStudent.StudentActive = true;

                // Setting an ID for new student by finding total number of records and incrementing by one.
                int count = db.tblStudents.Count(); count++;
                tblStudent.StudentID = "student" + count;

                // Setting an admission date that is the exact date student is created.
                tblStudent.StudentAdmissionDate = DateTime.Today.ToShortDateString();

                db.tblStudents.Add(tblStudent);
                db.SaveChanges();

                // Take user to index right after submission is done.
                return(RedirectToAction("Index"));
            }

            ViewBag.ClassID   = new SelectList(db.tblClasses, "ClassID", "ClassName");
            ViewBag.SectionID = new SelectList(db.tblSections, "SectionID", "SectionName", tblStudent.SectionID);
            ViewBag.StudentID = new SelectList(db.tblUsers, "UserID", "UserName", tblStudent.StudentID);

            return(View(tblStudent));
        }
Пример #11
0
        public ActionResult Create([Bind(Include = "FacultyName,FacultyEmail,FacultySpecification,FacultyGender")] tblFaculty tblFaculty)
        {
            if (ModelState.IsValid)
            {
                // Setting Active to true, because it is a new field.
                tblFaculty.FacultyActive = true;

                // Creating an ID for Faculty based on total records + 1.
                int count = db.tblFaculties.Count(); count++;
                tblFaculty.FacultyID = "faculty" + count;   // Setting the Faculty ID

                // Joining date set to current date.
                tblFaculty.FacultyJoiningDate = DateTime.Today.Date.ToShortDateString();

                db.tblFaculties.Add(tblFaculty);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            ViewBag.FacultyID = new SelectList(db.tblUsers, "UserID", "UserName", tblFaculty.FacultyID);
            return(View(tblFaculty));
        }
Пример #12
0
        public ActionResult Register([Bind(Include = "UserTypeID")] tblUser user, string RollNo, string StaffNo)
        {
            // Checking if the user is a Student (Type ID 2)
            if (user.UserTypeID == 2)
            {
                // Checking if a student exists in database.
                int stdcount = db.tblStudents.Where(t => t.StudentID == RollNo).Count();

                // If a student exists, accept submission for account.
                if (stdcount > 0)
                {
                    // Check if an account of the same student is already registered.
                    int count = db.tblUsers.Where(t => t.StudentNo == RollNo).Count();

                    // If there is no submission or account already present, submit the request.
                    if (count == 0)
                    {
                        // Setting Roll number / Employee number, Active value, Request date, and Registration Status.
                        user.StudentNo       = RollNo;
                        user.UserActive      = true;
                        user.UserRequestDate = DateTime.Now.ToShortDateString();
                        user.UserRegStatus   = "Requested";

                        db.tblUsers.Add(user);
                        db.SaveChanges();
                    }
                    else
                    {
                        // TODO: Show an error, as the student request has already been submitted.
                        //ViewBag.ShowError = "Student Request has already been submitted!";
                    }
                }
                else
                {
                    // TODO: Show an error, as the student record does not exist.

                    // The code below kinda works, but it sends the user to another page filled with errors.
                    // We don't want that to happen, therefore there is a need to search for alternatives.
                    //return HttpNotFound("Student record does not exist!");
                }
            }
            // Checking if the user is Faculty / Staff (Type ID 3)
            else if (user.UserTypeID == 3)
            {
                // Checking if a faculty exists in database.
                int Fcount = db.tblFaculties.Where(t => t.FacultyID == StaffNo).Count();

                // If a faculty exists, accept submission for account.
                if (Fcount > 0)
                {
                    // Check if an account of the same faculty member is already registered.
                    int count = db.tblUsers.Where(t => t.StaffNo == StaffNo).Count();

                    // If there is no submission or account already present, submit the request.
                    if (count == 0)
                    {
                        // Setting Staff No, Active, Submission request date, and Registration Status.
                        user.StaffNo         = StaffNo;
                        user.UserActive      = true;
                        user.UserRequestDate = DateTime.Now.ToShortDateString();
                        user.UserRegStatus   = "Requested";

                        db.tblUsers.Add(user);
                        db.SaveChanges();
                    }
                    else
                    {
                        // TODO: Show an error, as the faculty request has already been submitted.
                        //ViewBag.ShowError = "Staff Request has already been submitted!";
                    }
                }
                else
                {
                    // TODO: Show an error, as the faculty record does not exist.
                    //ViewBag.ShowError = "Staff record does not exist!";
                }
            }

            ViewBag.UserTypeID = new SelectList(db.tblUserTypes.Where(x => x.UserTypeID != 4), "UserTypeID", "UserTypeName");
            return(View());
        }