コード例 #1
0
        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));
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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;
            }
        }
コード例 #5
0
        public OperationDetails UpdateTodoList(TodoListDTO todoList)
        {
            var todoListEntity = new TodoListEntity
            {
                Name = todoList.Name
            };

            _todoListRepository.Update(todoListEntity);
            db.Commit();
            return(new OperationDetails(true, "TodoList успешно обновлен", ""));
        }
コード例 #6
0
        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"));
        }
コード例 #7
0
        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 успешно добавлен", ""));
        }
コード例 #8
0
        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);
        }
コード例 #9
0
 public void Delete(TodoListEntity item)
 {
     _todoListDbSet.Remove(item);
 }
コード例 #10
0
 public void Create(TodoListEntity item)
 {
     //_todoListDbSet.Add(item);
     _db.Set <TodoListEntity>().Add(item);
 }