public JsonResult Add(CreateInspectionAreaRequest request)
        {
            if (request.InspectionAreaID <= 0)
            {
                InspectionArea inspectionArea = new InspectionArea();
                inspectionArea.InspectionAreaID = request.InspectionAreaID;
                inspectionArea.AreaID = request.AreaID;

                db.InspectionAreas.Add(inspectionArea);
                db.SaveChanges();
            }
            else
            {
                InspectionArea inspectionArea = db.InspectionAreas.Where(x => x.InspectionAreaID == request.InspectionAreaID).FirstOrDefault();
                if (inspectionArea != null)
                {
                    inspectionArea.InspectionAreaID = request.InspectionAreaID;
                    inspectionArea.AreaID = request.AreaID;

                    db.SaveChanges();
                }

            }

            return Json("true");
        }
Exemplo n.º 2
0
        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);
        }