public ActionResult Create(Layout layout)
        {
            if (ModelState.IsValid)
            {
                db.Layouts.Add(layout);
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            var userId = (Guid)Membership.GetUser().ProviderUserKey;

            return View("Crud", new LayoutModel
                                    {
                                        Layout = layout,
                                        Companies = db.Companies.Where(c => userId == c.OwnerId),
                                        OperationType = OperationType.Create
                                    });
        }
 public ActionResult Edit(Layout layout, int companyId)
 {
     layout.Company = db.Companies.Find(companyId);
     foreach (var element in layout.Elements)
     {
         if (element.ElementId == 0) db.Elements.Add(element);
         else db.Entry(element).State = EntityState.Modified;
     }
     if (ModelState.IsValid)
     {
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View("Crud", new LayoutModel
                             {
                                 Layout = layout,
                                 Companies = new[] { layout.Company },
                                 OperationType = OperationType.Edit
                             });
 }