예제 #1
0
        public ActionResult HireAction(int?id)
        {
            ViewBag.drpAssert     = CommonController.drpAssert();
            ViewBag.drpEnrollment = CommonController.drpEnrollment();

            if (id != 0)
            {
                InstrumentHire dataset = entities.InstrumentHires.Find(id);
                return(PartialView(dataset));
            }

            else
            {
                return(PartialView());
            }
        }
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            ValidationResult validationResult = ValidationResult.Success;

            try
            {
                var otherPropertyInfo = validationContext.ObjectType.GetProperty(this.otherPropertyName);
                if (otherPropertyInfo.PropertyType.Equals(new Int32().GetType()))
                {
                    int EnrolmentID        = (int)value;
                    int InstrumentAssertID = (int)otherPropertyInfo.GetValue(validationContext.ObjectInstance, null);

                    using (IN705_201802_arulr1Entities1 entity = new IN705_201802_arulr1Entities1())
                    {
                        Enrolment        enrolment        = entity.Enrolments.Where(f => f.EnrolmentID == EnrolmentID).FirstOrDefault();
                        InstrumentAssert instrumentAssert = entity.InstrumentAsserts.Where(f => f.InstrumentAssertID == InstrumentAssertID).FirstOrDefault();
                        InstrumentHire   instrumentHire   = entity.InstrumentHires.Where(f => f.EnrolmentID == enrolment.EnrolmentID && f.InstrumentAssertID == instrumentAssert.InstrumentAssertID).FirstOrDefault();
                        if (enrolment.Lessonbatch.Lesson.InstrumentID == instrumentAssert.InstrumentID && instrumentHire == null)
                        {
                            return(ValidationResult.Success);
                        }
                        else if (enrolment.Lessonbatch.Lesson.InstrumentID != instrumentAssert.InstrumentID)
                        {
                            return(new ValidationResult("Enrolment can't hire this instrument."));
                        }
                        else if (instrumentHire != null)
                        {
                            return(new ValidationResult("Enrolment currently has an instrument hired."));
                        }
                        else
                        {
                            return(new ValidationResult("Enrolment can't hire this instrument and currently has an instrument hired."));
                        }
                    }
                }
                else
                {
                    validationResult = new ValidationResult("An error occurred while validating the property.");
                }
            }
            catch (Exception)
            {
                return(new ValidationResult("Enrolment can't hire this instrument."));
            }

            return(validationResult);
        }
예제 #3
0
        public ActionResult HireAction(InstrumentHire instrumenthire)
        {
            ModelState.Remove("InstrumentHireId");

            if (ModelState.IsValid)
            {
                string msg = "";

                if (instrumenthire.InstrumentHireId > 0)
                {
                    var dataset = entities.InstrumentHires.Where(f => f.InstrumentHireId == instrumenthire.InstrumentHireId).FirstOrDefault();
                    if (dataset != null)
                    {
                        dataset.Description        = instrumenthire.Description;
                        dataset.InstrumentAssertID = instrumenthire.InstrumentAssertID;
                        dataset.EnrolmentID        = instrumenthire.EnrolmentID;
                        dataset.InstrumentAssert.InstrumentConditionID = 3;
                        msg = "Hire details Updated Successfully";
                    }
                }
                else
                {
                    entities.InstrumentHires.Add(instrumenthire);
                    InstrumentAssert datasetassert = entities.InstrumentAsserts.Where(f => f.InstrumentAssertID == instrumenthire.InstrumentAssertID).FirstOrDefault();
                    datasetassert.InstrumentConditionID = 3;
                    msg = "New Hire details Added successfully";
                }
                entities.SaveChanges();
                return(new JsonResult
                {
                    Data = new
                    {
                        success = true,
                        action = "Hire",
                        message = msg
                    },
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet
                });
            }
            ViewBag.drpAssert     = CommonController.drpAssert();
            ViewBag.drpEnrollment = CommonController.drpEnrollment();

            return(PartialView(instrumenthire));
        }
예제 #4
0
        public IActionResult Enroll(Enroll model)
        {
            if (ModelState.IsValid)
            {
                var  user          = _db.Person.Where(p => p.Email == User.Identity.Name).Single();
                bool studentExists = 0 < _db.Students.Where(s => s.PersonId == user.PersonId).Count();

                if (!studentExists)
                {
                    var student = new Students();
                    student.PersonId = user.PersonId;

                    _db.Students.Add(student);
                    _db.SaveChanges();
                }

                var insertedStudent = _db.Students.Where(s => s.PersonId == user.PersonId).Single();
                if (!studentExists)
                {
                    var studentguardian = new StudentGuardians();
                    studentguardian.StudentId    = insertedStudent.StudentId;
                    studentguardian.ContactPhone = model.GuardianPhone;
                    studentguardian.Email        = model.GuardianEmail;
                    studentguardian.FirstName    = model.GuardianFirstname;
                    studentguardian.LastName     = model.GuardianLastname;

                    _db.StudentGuardians.Add(studentguardian);
                }



                var enrollment = new Enrollment();

                enrollment.StudentId    = insertedStudent.StudentId;
                enrollment.InstrumentId = model.instrumentID;
                enrollment.LessonLevel  = model.LessonLevel;

                _db.Enrollment.Add(enrollment);


                if (model.instrumentHire)
                {
                    var hire = new InstrumentHire();

                    hire.StudentId    = insertedStudent.StudentId;
                    hire.InstrumentId = model.instrumentID;

                    _db.InstrumentHire.Add(hire);
                }

                if (!studentExists)
                {
                    if (model.LessonLevel < 4)
                    {
                        var ensemble = new EnsembleMusicians();
                        ensemble.EnsembleId = 0;
                        ensemble.PersonId   = user.PersonId;

                        _db.EnsembleMusicians.Add(ensemble);
                    }
                    else if (model.LessonLevel > 6)
                    {
                        var ensemble = new EnsembleMusicians();
                        ensemble.EnsembleId = 2;
                        ensemble.PersonId   = user.PersonId;

                        _db.EnsembleMusicians.Add(ensemble);
                    }
                    else
                    {
                        var ensemble = new EnsembleMusicians();
                        ensemble.EnsembleId = 1;
                        ensemble.PersonId   = user.PersonId;

                        _db.EnsembleMusicians.Add(ensemble);
                    }
                }

                _db.SaveChanges();
                return(RedirectToAction("Index", "Home"));
            }

            return(View());
        }