public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestMessage req, TraceWriter log) { log.Info("CreateTodoList Invoked."); string body = await req.Content.ReadAsStringAsync(); ITodoList <IEnumerable <Item> > newList = JsonConvert.DeserializeObject <TodoList>(body); log.Info($"CreateTodoList Name: {newList.Name}."); // Define the row, string newItemGuid = Guid.NewGuid().ToString(); // Create the Entity and set the partition to signup, TodoListEntity listEntity = new TodoListEntity("todovue", newItemGuid); listEntity.Id = newItemGuid; listEntity.Name = newList.Name; listEntity.Items = JsonConvert.SerializeObject(new List <Item>()); TodoListTableStorage storage = new TodoListTableStorage(); CloudTable table = storage.GetCloudTableReference(); TableOperation insertOperation = TableOperation.Insert(listEntity); await table.ExecuteAsync(insertOperation); newList.Id = newItemGuid; return(req.CreateResponse(HttpStatusCode.OK, newList)); }
public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "PUT", Route = null)] HttpRequestMessage req, TraceWriter log) { log.Info("UpdateTodoList Invoked."); string body = await req.Content.ReadAsStringAsync(); ITodoList <IEnumerable <Item> > inputList = JsonConvert.DeserializeObject <TodoList>(body); log.Info($"UpdateTodoList Id: {inputList.Name}."); TodoListEntity updateEntity = new TodoListEntity("todovue", inputList.Id); updateEntity.Items = JsonConvert.SerializeObject(inputList.Items); updateEntity.Name = inputList.Name; updateEntity.Id = inputList.Id; updateEntity.ETag = "*"; //By default, the SDK enforces optimistic concurrency via ETags. Set this value to '*' in order to force an overwrite to an entity as part of an update operation. TableOperation operation = TableOperation.Replace(updateEntity); TodoListTableStorage storage = new TodoListTableStorage(); CloudTable table = storage.GetCloudTableReference(); await table.ExecuteAsync(operation); return(req.CreateResponse(HttpStatusCode.NoContent)); }
public static TodoListEntity ConverToEntity(this TodoList todoItem) { var newValue = new TodoListEntity(); newValue.IsActive = todoItem.IsActive; newValue.ListId = todoItem.ListId; newValue.Title = todoItem.Title; return(newValue); }
public void Update(TodoListEntity item) { var entity = _todoListDbSet.Find(item.Id); if (entity != null) { entity.Name = item.Name; entity.ApplicationUserEntityId = item.ApplicationUserEntityId; _db.Entry(item).State = EntityState.Modified; } }
public OperationDetails UpdateTodoList(TodoListDTO todoList) { var todoListEntity = new TodoListEntity { Name = todoList.Name }; _todoListRepository.Update(todoListEntity); db.Commit(); return(new OperationDetails(true, "TodoList успешно обновлен", "")); }
public OperationDetails DeleteTodoList(TodoListDTO todoList) { TodoListEntity todoListEntity = _todoListRepository.GetTodoListById(todoList.Id); if (todoListEntity != null) { _todoListRepository.Delete(todoListEntity); db.Commit(); return(new OperationDetails(true, "TodoList успешно удален", "")); } return(new OperationDetails(false, "TodoList, который должен быть удален отсутствует", "Id")); }
public OperationDetails CreateTodoList(TodoListDTO todoList) { TodoListEntity todoListEntity = new TodoListEntity { ApplicationUserEntityId = todoList.ApplicationUserEntityId, Name = todoList.Name }; _todoListRepository.Create(todoListEntity); db.Commit(); return(new OperationDetails(true, "TodoList успешно добавлен", "")); }
public async Task <TodoList> CreateTodoList(string title) { var newLsit = new TodoListEntity(); newLsit.Title = title; var todoLists = await uow.TodoListRepository.GetAll().ConfigureAwait(false); if (!todoLists.Any()) { newLsit.IsActive = true; } if (await newLsit.Save(uow.TodoListRepository).ConfigureAwait(false)) { return(newLsit.ConverToDto()); } return(null); }
public void Delete(TodoListEntity item) { _todoListDbSet.Remove(item); }
public void Create(TodoListEntity item) { //_todoListDbSet.Add(item); _db.Set <TodoListEntity>().Add(item); }