Ejemplo n.º 1
0
        public JsonResult Add(CreateAreaRequest request)
        {
            Area area = null;
            if (request.AreaID <= 0)
            {
                area = new Area();
                area.AreaID = request.AreaID;
                area.Name = request.Name;

                db.Areas.Add(area);
                db.SaveChanges();
            }
            else
            {
                 area = db.Areas.Where(x => x.AreaID == request.AreaID).FirstOrDefault();
                if (area != null)
                {
                    area.AreaID = request.AreaID;
                    area.Name = request.Name;                    

                    db.SaveChanges();
                }

            }

            return Json(area);
        }
Ejemplo n.º 2
0
 public JsonResult AddFromTemplate(int AreaTemplateID,int PropertyID)
 {
     Area area = null;
     bool added = false;
     if (AreaTemplateID>0&&PropertyID>0)
     {
         area = new Area();
         LandlordTemplateArea templateArea = db.LandlordTemplateAreas.Where(x => x.LandlordTemplateAreaID == AreaTemplateID).FirstOrDefault();
         area.Name = templateArea.AreaName;
         area.PropertyID = PropertyID;
         db.Areas.Add(area);
         db.SaveChanges();
         List<LandlordTemplateAreaItem> templateAreaItems = db.LandlordTemplateAreaItems.Where(y => y.LandlordTemplateAreaID == AreaTemplateID).ToList();
         foreach (var templateAreaItem in templateAreaItems)
         {
             AreaItem item = new AreaItem();
             item.AreaID = area.AreaID;
             item.RoomDescription = "";
             item.RoomItem = templateAreaItem.ItemName;
             db.AreaItems.Add(item);
         }
         db.SaveChanges();
         added = true;
     }
     return Json(added, JsonRequestBehavior.AllowGet);
 }