Beispiel #1
0
        public ActionResult AssertAction(InstrumentAssert instrumentassert)
        {
            ModelState.Remove("InstrumentAssertID");
            ModelState.Remove("InstrumentCode");

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

                if (instrumentassert.InstrumentAssertID > 0)
                {
                    var dataset = entities.InstrumentAsserts.Where(f => f.InstrumentAssertID == instrumentassert.InstrumentAssertID).FirstOrDefault();
                    if (dataset != null)
                    {
                        Instrument instument = entities.Instruments.Where(x => x.InstrumentID == instrumentassert.InstrumentID).FirstOrDefault();
                        String     code      = "SMMS_" + instument.Name + "_00" + instrumentassert.InstrumentAssertID;
                        dataset.InstrumentCode        = code;
                        dataset.InstrumentID          = instrumentassert.InstrumentID;
                        dataset.InstrumentConditionID = instrumentassert.InstrumentConditionID;
                        msg = "Instrument Updated Successfully";
                    }
                }
                else
                {
                    Instrument instument = entities.Instruments.Where(x => x.InstrumentID == instrumentassert.InstrumentID).FirstOrDefault();
                    try
                    {
                        var    insAssert = entities.InstrumentAsserts.Max(x => x.InstrumentAssertID) + 1;
                        String code      = "SMMS_" + instument.Name + "_00" + insAssert;
                        instrumentassert.InstrumentCode = code;
                    }
                    catch
                    {
                        String code = "SMMS_" + instument.Name + "_00" + 1;
                        instrumentassert.InstrumentCode = code;
                    }

                    entities.InstrumentAsserts.Add(instrumentassert);
                    msg = "Instrument Added successfully";
                }
                entities.SaveChanges();
                return(new JsonResult
                {
                    Data = new
                    {
                        success = true,
                        action = "Assert",
                        message = msg
                    },
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet
                });
            }
            ViewBag.drpInstrument          = CommonController.drpInstrument();
            ViewBag.drpInstrumentCondition = CommonController.drpInstrumentCondition();

            return(PartialView(instrumentassert));
        }
        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);
        }
Beispiel #3
0
        public ActionResult ServiceAction(InstumentService service)
        {
            ModelState.Remove("InstumentServiceID");

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

                if (service.InstumentServiceID > 0)
                {
                    var dataset = entities.InstumentServices.Where(f => f.InstumentServiceID == service.InstumentServiceID).FirstOrDefault();
                    if (dataset != null)
                    {
                        dataset.Problem          = service.Problem;
                        dataset.Date             = service.Date;
                        dataset.Comments         = service.Comments;
                        dataset.InstrumentHireId = service.InstrumentHireId;
                        dataset.TechnicianID     = service.TechnicianID;
                        InstrumentAssert instrumentAssert = entities.InstrumentAsserts.Where(f => f.InstrumentAssertID == service.InstrumentHire.InstrumentAssertID).FirstOrDefault();
                        instrumentAssert.InstrumentConditionID = 2;
                        msg = "Instrument service Updated Successfully";
                    }
                }
                else
                {
                    entities.InstumentServices.Add(service);
                    InstrumentAssert instrumentAssert = entities.InstrumentAsserts.Where(f => f.InstrumentAssertID == service.InstrumentHire.InstrumentAssertID).FirstOrDefault();
                    instrumentAssert.InstrumentConditionID = 2;
                    msg = "Instrument Added successfully";
                }
                entities.SaveChanges();
                return(new JsonResult
                {
                    Data = new
                    {
                        success = true,
                        action = "Service",
                        message = msg
                    },
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet
                });
            }
            ViewBag.drpInstrumentHire = CommonController.drpInstrumentHire();
            ViewBag.drpTechnician     = CommonController.drpTechnician();

            return(PartialView(service));
        }
Beispiel #4
0
        public ActionResult AssertAction(int?id)
        {
            ViewBag.drpInstrument          = CommonController.drpInstrument();
            ViewBag.drpInstrumentCondition = CommonController.drpInstrumentCondition();


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

            else
            {
                return(PartialView());
            }
        }
Beispiel #5
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));
        }