private void detach_Warehouses(Warehouse entity)
		{
			this.SendPropertyChanging();
			entity.Project = null;
		}
        public ActionResult Save(Warehouse model, FormCollection collection)
        {
            Warehouse warehouse;
            if (model.Id <= 0)
            {
                model.DateCreated = DateTime.Now;
                DataContext.Warehouses.InsertOnSubmit(model);
                DataContext.SubmitChanges();

                warehouse = model;

                ShowSuccess("Склад был успешно создан");
            }
            else
            {
                warehouse = DataContext.Warehouses.FirstOrDefault(p => p.Id == model.Id);
                if (warehouse == null)
                {
                    ShowSuccess("Такой склад не найден");
                    return RedirectToAction("Index");
                }

                warehouse.Title = model.Title;
                warehouse.Description = model.Description;
                warehouse.City = model.City;
                warehouse.Address = model.Address;
                warehouse.DateModified = DateTime.Now;
                if (model.ProjectId != warehouse.ProjectId)
                {
                    warehouse.Project.Warehouses.Remove(warehouse);
                    DataContext.Projects.First(p => p.Id == model.Id).Warehouses.Add(warehouse);
                }
                DataContext.SubmitChanges();

                ShowSuccess(string.Format("Склад {0} был успешно отредактирован", model.Title));
            }

            // Обновляем пермишенны для роли
            warehouse.WarehouseKeepers.Clear();
            foreach (var userId in collection.AllKeys.Where(k => k.StartsWith("user_")).Select(key => Convert.ToInt64(key.Split('_')[1])))
            {
                warehouse.WarehouseKeepers.Add(new WarehouseKeeper()
                {
                    Warehouse = warehouse,
                    UserId = userId,
                    DateCreated = DateTime.Now
                });
            }
            DataContext.SubmitChanges();

            return RedirectToAction("Index");
        }
		private void attach_Warehouses(Warehouse entity)
		{
			this.SendPropertyChanging();
			entity.Project = this;
		}