public void Create(ContainerView containerView, long structure, long? parent) { if (containerView == null) throw new ArgumentNullException("containerView"); var container = containerView.Convert(); if (parent != null) { var parentobj = _dbContext.Containers.Find(parent); container.ContainerPrototype = parentobj.ContainerPrototype.Childs.First(); container.ParentContainer = parentobj; } else { container.ContainerPrototype = _dbContext.ContainerPrototypes.Where(cp => cp.StructureId == structure && cp.Parent == null). SingleOrDefault(); } _dbContext.Containers.Add(container); _dbContext.SaveChanges(); //TODO return container view containerView.Id = container.Id; //TODO try { InvokeOnCreateContainer(container); } catch { //TODO ROLLBACK throw; } }
public void Create(ContainerView containerView, long structure, string containerPrototype, long parentContainer) { if (containerView == null) throw new ArgumentNullException("containerView"); var container = containerView.Convert(); var containerPrototypeObj = ContainerPrototypeManager.Get(_dbContext, structure, containerPrototype); if (containerPrototypeObj == null) throw new ArgumentException("Invalid argument"); var parentContainerObj = Get(_dbContext, parentContainer); if (containerPrototypeObj.Parent.Name != parentContainerObj.ContainerPrototype.Name) throw new Exception(); container.ParentContainer = parentContainerObj; container.ContainerPrototype = containerPrototypeObj; _dbContext.Containers.Add(container); _dbContext.SaveChanges(); //TODO return container view containerView.Id = container.Id; //TODO try { InvokeOnCreateContainer(container); } catch { //TODO ROLLBACK throw; } }