public UnitDomainModel CreateUnit(UnitDomainModel model) { if (model.ParentUnitId.HasValue) { var parent = unitRepository.GetUnitById(model.ParentUnitId.Value); model.RootUnitId = parent.RootUnitId; } return unitRepository.CreateUnit(model); }
public void UpdateUnit(UnitDomainModel model) { unitRepository.UpdateUnit(model); }
private bool AreAllChildsInactive(UnitDomainModel unit) { bool result = true; foreach (var item in unit.ChildUnits) { result = result && !item.IsActive; if (item.ChildUnits.Count > 0) { result = result && AreAllChildsInactive(item); } } return result; }
public void UpdateUnit(UnitDomainModel model) { var unit = unitsInContext .Include(e => e.UnitClassifications) .SingleOrDefault(e => e.UnitId == model.UnitId); if (unit == null) { throw new Exception(string.Format("Unit with ID = {0} does not exist.", model.UnitId)); } //only Name and classifications can be updated unit.Name = model.Name; var original = unit.UnitClassifications; var modified = model.Classifications.Select(e => new UnitClassification { UnitId = model.UnitId, ClassificationId = e.ClassificationId, ClassificationPermissionId = e.ClassificationPermissionId } ); var removed = original.Where(e => !modified.Contains(e)).ToList(); var added = modified.Where(e => !original.Contains(e)).ToList(); var unitClassificationContext = unitOfWork.DbContext.Set<UnitClassification>(); unitClassificationContext.RemoveRange(removed); unitClassificationContext.AddRange(added); using (var transaction = unitOfWork.BeginTransaction()) { unitOfWork.Save(); docRepository.spSetUnitTokens(unit.UnitId); transaction.Commit(); } }
public UnitDomainModel CreateUnit(UnitDomainModel model) { var unit = new Unit { Name = model.Name, IsActive = true, UnitTypeId = (int)Enum.Parse(typeof(Models.DomainModels.UnitType), model.Type), UnitRelations = new List<UnitRelation> { new UnitRelation { ParentUnitId = model.ParentUnitId, RootUnitId = model.ParentUnitId.HasValue ? model.RootUnitId : model.UnitId } }, UnitClassifications = new List<UnitClassification>() }; foreach (var item in model.Classifications) { unit.UnitClassifications.Add(new UnitClassification { ClassificationId = item.ClassificationId, ClassificationPermissionId = item.ClassificationPermissionId }); } using (var transaction = unitOfWork.BeginTransaction()) { unitsInContext.Add(unit); unitOfWork.Save(); docRepository.spSetUnitTokens(unit.UnitId); transaction.Commit(); } return new UnitDomainModel { UnitId = unit.UnitId, Name = unit.Name, Type = ((Models.DomainModels.UnitType)unit.UnitTypeId).ToString(), IsActive = unit.IsActive, RootUnitId = unit.UnitRelations.FirstOrDefault().RootUnitId, ParentUnitId = unit.UnitRelations.FirstOrDefault().ParentUnitId, }; }
public void AddChild(UnitDomainModel item) { ChildUnits.Add(item); }
public IHttpActionResult CreateUnit(UnitDomainModel model) { return Ok(unitBusinessLogic.CreateUnit(model)); }
public IHttpActionResult UpdateUnit(int unitId, UnitDomainModel model) { unitRepository.UpdateUnit(model); return Ok(); }