public DTO.InsertResult InsertLocation(DTO.Location location) { lock (_serviceManager) { var repository = _repositoryFactory.CreateRepository<Guid, CoreEntity.Location>(); CoreEntity.Location corelocation = _engine.Map<DTO.Location, CoreEntity.Location>(location); try { corelocation = _serviceManager.PrepareLocation(corelocation); } catch (LocationCollisionException lce) { return new DTO.InsertResult() { Conflict = _engine.Map<CoreEntity.Location, DTO.Location>(lce.Conflict), Result = false }; } if (repository.Add(corelocation)) { _logger.Debug("Insert new location " + corelocation.Name + corelocation.Description); return new DTO.InsertResult() {Result = true}; } _logger.Warn("Not possible to insert location: "); return new DTO.InsertResult() { Result = false }; } }
public DTO.InsertResult UpdateLocation(DTO.Location oldlocation, DTO.Location newlocation) { lock (_serviceManager) { var repository = _repositoryFactory.CreateRepository<Guid, CoreEntity.Location>(); var oldcorelocation = repository.All().FirstOrDefault(x => x.Name==oldlocation.Name); CoreEntity.Location newcorelocation = _engine.Map<DTO.Location, CoreEntity.Location>(newlocation); if (oldcorelocation.Name != newcorelocation.Name) oldcorelocation.Name = newcorelocation.Name; if (oldcorelocation.Description != newcorelocation.Description) oldcorelocation.Description = newcorelocation.Description; oldcorelocation.TasksList = newcorelocation.TasksList; foreach (CoreEntity.Task task in oldcorelocation.TasksList) task.Location = oldcorelocation; if (repository.Update(oldcorelocation)) { _logger.Debug("Updated location " + oldcorelocation.Name + " " + oldcorelocation.Description + " in " + newcorelocation.Name + " " + oldcorelocation.Description); return new DTO.InsertResult() { Result = true }; } _logger.Warn("Not possible to update location: "); return new DTO.InsertResult() { Result = false }; } }