public XioResult <ClientModel> GetClient(ClientSpecModel model) { log.DescribeOperation("GetClient"); if (model.MicrosoftTenantId != Guid.Empty) { var existing = db.Clients.SingleOrDefault(x => x.MicrosoftTenantId == model.MicrosoftTenantId); if (existing != null) { log.LogInformation("GetClient returned existing client.", ("client", existing.UrlPart)); return(new XioResult <ClientModel>(true, mapper.Map <ClientModel>(existing))); } } if (!string.IsNullOrWhiteSpace(model.UrlPart)) { var existing = db.Clients.SingleOrDefault(x => x.UrlPart == model.UrlPart); if (existing != null) { log.LogInformation("GetClient returned existing client.", ("client", existing.UrlPart)); return(new XioResult <ClientModel>(true, mapper.Map <ClientModel>(existing))); } } if (model.Id > 0) { var existing = db.Clients.SingleOrDefault(x => x.Id == model.Id); if (existing != null) { log.LogInformation("GetClient returned existing client.", ("client", existing.UrlPart)); return(new XioResult <ClientModel>(true, mapper.Map <ClientModel>(existing))); } } // this is a create var newClient = db.Clients.Add(new Client { CountryCode = model.CountryCode, PostCode = model.PostCode, ProviderId = 1, // todo: something with providder Title = model.Title, MicrosoftTenantId = model.MicrosoftTenantId, UrlPart = db.GetUrlPart <Client>(model.Title) }); db.SaveChanges(); log.LogInformation("GetClient created new client.", ("client", newClient.Entity.UrlPart)); return(new XioResult <ClientModel>(true, mapper.Map <ClientModel>(newClient.Entity))); }
public ProjectModel Execute(ProjectCreateModel model, ITaskTracker tracker) { tracker.SetStatusMessage($"Creating project '{model.Title}'"); var client = db.Clients.SingleOrDefault(x => x.Id == model.ClientId); var np = new Project { UrlPart = db.GetUrlPart <Project>(model.Title), ClientId = model.ClientId, Title = model.Title }; db.Projects.Add(np); db.SaveChanges(); tracker.SetStatusMessage("Beginning task..."); tracker.SetProgress(0, 3); Thread.Sleep(6000); tracker.LogInformation("Beginning thing to do."); tracker.SetProgress(1); Thread.Sleep(8000); tracker.LogWarning("Couldn't do this thing but continuing anyway."); tracker.SetProgress(2); Thread.Sleep(12000); tracker.SetProgress(3); Thread.Sleep(5000); tracker.Complete(true); return(tracker.StoreResult(new ProjectModel { UrlPart = np.UrlPart, Title = np.Title, Client = mapper.Map <ClientModel>(client) })); }