public JsonResult Completed(int id)
 {
     Inspection inspection = db.Inspections.Where(x => x.InspectionID == id).FirstOrDefault();
     inspection.Completed = true;
     db.SaveChanges();
     InspectionResponse response = new InspectionResponse()
     {
         InspectionID = inspection.InspectionID,
         Type = inspection.Type,
         Date = inspection.Date,
         EntityType = inspection.EntityType,
         EntityID = inspection.EntityID,
         HouseClean = inspection.HouseClean,
         HouseComments = inspection.HouseComments,
         CarpetsClean = inspection.CarpetsClean,
         CarpetsComments = inspection.CarpetsComments,
         GardenClean = inspection.GardenClean,
         GardenComments = inspection.GardenComments,
         PropertyID = inspection.PropertyID,
         PoolClean = inspection.PoolClean,
         PoolComments = inspection.PoolComments,
         OverallComments = inspection.OverallComments,
         Completed = inspection.Completed
     };
     return Json(response, JsonRequestBehavior.AllowGet);
 }
Example #2
0
 public InspectionItem(InspectionResponse response)
 {
     this.CarpetsClean = response.CarpetsClean;
     this.CarpetsComments = response.CarpetsComments;
     this.Date = response.Date;
     this.EntityID = response.EntityID;
     this.EntityType = response.EntityType;
     this.GardenClean = response.GardenClean;
     this.GardenComments = response.GardenComments;
     this.HouseClean = response.HouseClean;
     this.HouseComments = response.HouseComments;
     this.InspectionID = response.InspectionID;
     this.OverallComments = response.OverallComments;
     this.PoolClean = response.PoolClean;
     this.PoolComments = response.PoolComments;
     this.PropertyID = response.PropertyID;
     this.Type = response.Type;
     this.Completed = response.Completed ? "Y":"N";
 }
        public JsonResult Add(CreateInspectionRequest request)
        {
            Inspection inspection = new Inspection()
            {
                PropertyID = request.PropertyID,
                OverallComments = "Test on " + DateTime.Now.ToShortTimeString()
            };

            db.Inspections.Add(inspection);
            db.SaveChanges();

            var propertyAreas = db.Areas.Where(x => x.PropertyID == request.PropertyID).ToList();

            foreach (var propertyArea in propertyAreas)
            {
                InspectionArea area = new InspectionArea()
                {
                    InspectionID = inspection.InspectionID,
                    AreaID = propertyArea.AreaID
                };

                db.InspectionAreas.Add(area);
                db.SaveChanges();

                var areaItems = db.AreaItems.Where(x => x.AreaID == propertyArea.AreaID).ToList();

                foreach (var areaItem in areaItems)
                {
                    InspectionAreaItem item = new InspectionAreaItem()
                    {
                        InspectionAreaID = area.InspectionAreaID,
                        ItemID = areaItem.AreaItemID,
                        ItemDescription = areaItem.RoomItem,
                    };

                    db.InspectionAreaItems.Add(item);
                    db.SaveChanges();
                }
                
            }

            InspectionResponse response = new InspectionResponse();
            response.InspectionID = inspection.InspectionID;
            response.Completed = false;
            return Json(response);
        }