public async Task <OperationResult> SaveTaskAsync(SimpleTask record) { var validation = record.Validate(); if (!validation.IsValid) { return(new OperationResult(false, validation.ResultsToHtml())); } var endpoint = UriFactory.CreateDocumentCollectionUri(_db.DatabaseName, _db.TaskCollectionName); using (var client = _db.NewClient()) { ResourceResponse <Microsoft.Azure.Documents.Document> response; if (!string.IsNullOrEmpty(record.Id) && _db.DoesDocumentExists(_db.TaskCollectionName, record.Id)) { var task = _db.QueryTask(client).Where(t => t.Id == record.Id).AsEnumerable().FirstOrDefault(); if (task != null) { task.Title = record.Title; task.Description = record.Description; response = await client.UpsertDocumentAsync(endpoint, task, new RequestOptions()); return(new OperationResult(true) { RecordId = record.Id, Tag = response }); } } record.Id = string.IsNullOrEmpty(record.Id) ? Guid.NewGuid().ToString() : record.Id; record.RegistrationDateTime = DateTime.Now; record.State = new List <SimpleTaskStatus>() { new SimpleTaskStatus() { Id = Guid.NewGuid().ToString(), TaskId = record.Id, Status = TaskStatusType.New, RegistrationUser = record.User, RegistrationDate = DateTime.Now } }; response = await client.CreateDocumentAsync(endpoint, record); return(new OperationResult(true) { RecordId = record.Id }); } }
public async Task <OperationResult> SaveNotificationAsync(Notification record) { var validation = record.Validate(); if (!validation.IsValid) { return(new OperationResult(false, validation.ResultsToHtml())); } var endpoint = UriFactory.CreateDocumentCollectionUri(_db.DatabaseName, _db.NotificationCollectionName); using (var client = _db.NewClient()) { ResourceResponse <Microsoft.Azure.Documents.Document> response; if (!string.IsNullOrEmpty(record.Id) && _db.DoesDocumentExists(_db.NotificationCollectionName, record.Id)) { var notification = _db.QueryNotification(client).Where(t => t.Id == record.Id).AsEnumerable().FirstOrDefault(); if (notification != null) { notification.DeliveryDate = record.DeliveryDate; notification.DeliveryReponse = record.DeliveryReponse; notification.Destination = record.Destination; notification.Message = record.Message; notification.Sent = record.Sent; notification.Subject = record.Subject; response = await client.UpsertDocumentAsync(endpoint, notification, new RequestOptions()); return(new OperationResult(true) { RecordId = record.Id, Tag = response }); } } record.Id = string.IsNullOrEmpty(record.Id) ? Guid.NewGuid().ToString() : record.Id; record.RegistrationDate = DateTime.Now; response = await client.CreateDocumentAsync(endpoint, record); return(new OperationResult(true) { RecordId = record.Id, Tag = response }); } }