Ejemplo n.º 1
0
        public async Task <TodoVO> Update(TodoVO obj)
        {
            try
            {
                var old = _context.Todo.Where(p => p.Id == obj.Id).FirstOrDefault();
                if (old != null)
                {
                    old.Category  = obj.Category;
                    old.StartDate = obj.StartDate;
                    old.EndDate   = obj.EndDate;
                    old.TaskName  = obj.TaskName;
                    await _context.SaveChangesAsync();

                    return(obj);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                _logger.LogInformation(string.Format("Error trying update object with id = {0}.  Error message = {1}", obj.Id, ex.Message));
                return(obj);
            }
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> Insert([FromBody] TodoVO obj)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var item = _service.Insert(obj).Result;

            return(CreatedAtAction("Get", new { id = item.Id }, item));
        }
Ejemplo n.º 3
0
        public async Task <TodoVO> Update(TodoVO obj)
        {
            var old = _todo.Where(p => p.Id == obj.Id).FirstOrDefault();

            old.Category  = obj.Category;
            old.StartDate = obj.StartDate;
            old.EndDate   = obj.EndDate;
            old.TaskName  = obj.TaskName;
            return(obj);
        }
Ejemplo n.º 4
0
 public Todo LoadModel(TodoVO vo)
 {
     return(new Todo()
     {
         Id = vo.Id,
         Category = vo.Category,
         CreatedDate = vo.CreatedDate,
         EndDate = vo.EndDate,
         StartDate = vo.StartDate,
         TaskName = vo.TaskName
     });
 }
Ejemplo n.º 5
0
        public void Insert_InvalidObjectPassed_ReturnsBadRequest()
        {
            var nameMissingItem = new TodoVO()
            {
                Id = Guid.Parse("6da0e0a9-143e-466e-b594-4ddb3d0fb5d3"), TaskName = "Dentist"
            };

            _controller.ModelState.AddModelError("Category", "Required");
            var badResponse = _controller.Insert(nameMissingItem).Result;

            Assert.IsType <BadRequestObjectResult>(badResponse);
        }
Ejemplo n.º 6
0
        public void Insert_ValidObjectPassed_ReturnedResponseHasCreatedItem()
        {
            var testItem = new TodoVO()
            {
                Category = "Personal"
            };
            var createdResponse = _controller.Insert(testItem).Result as CreatedAtActionResult;
            var item            = createdResponse.Value as TodoVO;

            Assert.IsType <TodoVO>(item);
            Assert.Equal("Personal", item.Category);
        }
Ejemplo n.º 7
0
        public async Task <TodoVO> Insert(TodoVO obj)
        {
            try
            {
                _context.Todo.Add(new Todo().LoadModel(obj));
                await _context.SaveChangesAsync();

                return(obj);
            }
            catch (Exception ex)
            {
                _logger.LogInformation(string.Format("Error trying insert new record with id = {0}.  Error message = {1}", obj.Id, ex.Message));
                return(null);
            }
        }
Ejemplo n.º 8
0
        public void Insert_ValidObjectPassed_ReturnsCreatedResponse()
        {
            TodoVO item = new TodoVO()
            {
                Id          = Guid.Parse("6da0e0a9-143e-466e-b594-4ddb3d0fb5d3"),
                Category    = "Personal Appointment",
                CreatedDate = DateTime.Now,
                EndDate     = DateTime.Now.AddDays(2).AddHours(2),
                StartDate   = DateTime.Now.AddDays(2).AddHours(1),
                TaskName    = "Dentist"
            };
            var createdResponse = _controller.Insert(item).Result;

            Assert.IsType <CreatedAtActionResult>(createdResponse);
        }
Ejemplo n.º 9
0
        public void Update_ValidObjectPassed_ReturnedResponseHasCreatedItem()
        {
            var testItem = new TodoVO()
            {
                Id          = Guid.Parse("6da0e0a9-143e-466e-b594-4ddb3d0fb5d3"),
                Category    = "Personal Appointment",
                CreatedDate = DateTime.Now,
                EndDate     = DateTime.Now.AddDays(2).AddHours(2),
                StartDate   = DateTime.Now.AddDays(2).AddHours(1),
                TaskName    = "Dentist"
            };
            var createdResponse = _controller.Update(testItem).Result as CreatedAtActionResult;
            var item            = createdResponse.Value as TodoVO;

            Assert.IsType <TodoVO>(item);
            Assert.Equal("Personal Appointment", item.Category);
        }
Ejemplo n.º 10
0
        public async Task <ActionResult> Update(TodoVO obj)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var item = _service.Update(obj).Result;

            if (item != null)
            {
                return(CreatedAtAction("Get", new { id = item }, item));
            }
            else
            {
                return(NotFound());
            }
        }
Ejemplo n.º 11
0
 public async Task <TodoVO> Update(TodoVO obj)
 {
     return(await _todoRepository.Update(obj));
 }
Ejemplo n.º 12
0
 public async Task <TodoVO> Insert(TodoVO obj)
 {
     return(await _todoRepository.Insert(obj));
 }
Ejemplo n.º 13
0
 public async Task <TodoVO> Insert(TodoVO obj)
 {
     obj.Id = Guid.NewGuid();
     _todo.Add(obj);
     return(obj);
 }