コード例 #1
0
        /// <summary>
        /// Updates to do list.
        /// </summary>
        /// <param name="todolist">The todolist.</param>
        /// <returns></returns>
        public ToDoListDTO UpdateToDoList(ToDoListDTO todolist)
        {
            ToDoListEntity entity = _mapper.Map <ToDoListDTO, ToDoListEntity>(todolist);

            _repo.Update(entity, todolist.Id);
            return(todolist);
        }
コード例 #2
0
        public ToDoListDTO UpdateToDoList(Guid id, ToDoListDTO toDoListDTO, string email)
        {
            _logger.LogInformation("ToDoListService -> Executing UpdateToDoList()");

            //if the user didn't specify the date for the reminder
            if (toDoListDTO.EndDate == null)
            {
                toDoListDTO.IsReminded = false; //the list is not a reminded list
            }
            else
            {
                toDoListDTO.IsReminded = true;
            }

            ToDoList listToUpdate = _context
                                    .ToDoLists
                                    .Include(todo => todo.Items)
                                    .SingleOrDefault(todo => todo.Id.Equals(id) && todo.Owner.Equals(email));

            if (listToUpdate == null)
            {
                throw new EntityNotFoundException();
            }

            listToUpdate.UpdateData(toDoListDTO.CreateEntity(email));
            _context.SaveChanges();
            return(new ToDoListDTO(listToUpdate)); //return an updated dto
        }
コード例 #3
0
        public ActionResult <ToDoListDTO> Replace(int id, ToDoListDTO toDoListDTO)
        {
            toDoListDTO.Id = id;

            var toDoList = mapper.Map <ToDoList>(toDoListDTO);

            try
            {
                context.ToDoLists.Update(toDoList);
                context.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (context.ToDoLists.Find(id) == null)
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            toDoListDTO = mapper.Map <ToDoListDTO>(toDoList);

            return(toDoListDTO);
        }
コード例 #4
0
        public ToDoListDTO CreateToDoList(ToDoListDTO toDoListDTO, string email)
        {
            _logger.LogInformation("ToDoListService -> Executing CreateToDoList()");

            //if the user didn't specify the date for the reminder
            if (toDoListDTO.EndDate == null)
            {
                toDoListDTO.IsReminded = false; //the list is not a reminded list
            }
            else
            {
                toDoListDTO.IsReminded = true;
            }

            ToDoList newList = toDoListDTO.CreateEntity(email);

            //new todo list position is 'highest' in the hierarchy for the specified user
            newList.Position = _context.ToDoLists
                               .Where(x => x.Owner.Equals(email))
                               .Count();

            _context.ToDoLists.Add(newList);
            _context.SaveChanges();

            toDoListDTO.Id       = newList.Id;
            toDoListDTO.Position = newList.Position;

            return(toDoListDTO);
        }
コード例 #5
0
        /// <summary>
        /// Gets the by identifier.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <returns></returns>
        public ToDoListDTO GetById(long id)
        {
            var         entity = _repo.GetWithCondition <ToDoListEntity>(x => x.Id == id).FirstOrDefault();
            ToDoListDTO dto    = _mapper.Map <ToDoListEntity, ToDoListDTO>(entity);

            return(dto);
        }
コード例 #6
0
        /// <summary>
        /// Adds to do list.
        /// </summary>
        /// <param name="todolist">The todolist.</param>
        /// <returns></returns>
        public ToDoListDTO AddToDoList(ToDoListDTO todolist)
        {
            ToDoListEntity entity = _mapper.Map <ToDoListDTO, ToDoListEntity>(todolist);

            entity.CreatedDate = DateTime.Now;
            _repo.Add(entity);
            return(todolist);
        }
コード例 #7
0
 public ActionResult <ToDoListDTO> AddToDoList(ToDoListDTO todolist)
 {
     _logger.Info(() => "Api AddProduct");
     todolist.CreatedBy = (long)HttpContext.Request.HttpContext.Items["Userid"];
     todolist.UpdatedBy = (long)HttpContext.Request.HttpContext.Items["Userid"];
     _toDoListService.AddToDoList(todolist);
     return(StatusCode((int)HttpStatusCode.OK, todolist));
 }
コード例 #8
0
        public ActionResult CreateToDoList([FromBody] ToDoListDTO list)
        {
            _logger.LogInformation("ToDoList.CreateToDoList() executed!");

            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            return(CreatedAtAction(nameof(GetToDoList), new { id = list.Id }, new ToDoListDTO(_service.CreateToDoList(list, User.GetEmail()))));
        }
コード例 #9
0
        public void AddToDoList_InValidData()
        {
            ToDoListEntity entity = null;
            ToDoListDTO    dto    = null;

            _mapper.Setup(p => p.Map <ToDoListDTO, ToDoListEntity>(dto)).Returns(entity);
            _repo.Setup(p => p.Add(entity)).Returns(0);
            var returnObj = _toDoListService.AddToDoList(dto);

            Assert.IsTrue(returnObj == null);
        }
コード例 #10
0
        public ToDoList CreateToDoList(ToDoListDTO list, string owner)
        {
            ToDoList result = list.ToEntity();

            result.Position = _context.ToDoLists.Where(l => l.Owner == owner).Count();
            result.Reminded = true;
            result.Owner    = owner;
            _context.ToDoLists.Add(result);
            _context.SaveChanges();

            return(result);
        }
コード例 #11
0
        public void AddToDoItem_ValidData()
        {
            var dto = new ToDoListDTO {
                Id = 11, Description = "List_11", LabelId = 1, CreatedBy = 1, UpdatedBy = 1, CreatedDate = DateTime.Now, UpdatedDate = DateTime.Now
            };

            _todoListService.Setup(p => p.AddToDoList(dto)).Returns(dto);
            var returnObj   = todoListController.AddToDoList(dto);
            var okResult    = returnObj.Result as ObjectResult;
            var valueResult = okResult.Value as ToDoListDTO;

            Assert.AreEqual(11, valueResult.Id);
        }
コード例 #12
0
        public async Task <bool> Update(ToDoListDTO toDoListDTO)
        {
            var stringContent = new StringContent(JsonConvert.SerializeObject(toDoListDTO), Encoding.UTF8, "application/json");
            var response      = await _httpClient.PutAsync("todolist", stringContent);

            if (response.IsSuccessStatusCode)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #13
0
 public ActionResult <ToDoListDTO> Create(ToDoListDTO toDoListDTO)
 {
     if (toDoListDTO != null)
     {
         var toDoList = mapper.Map <ToDoList>(toDoListDTO);
         context.ToDoLists.Add(toDoList);
         context.SaveChanges();
         toDoListDTO = mapper.Map <ToDoListDTO>(toDoList);
         return(toDoListDTO);
     }
     else
     {
         return(BadRequest());
     }
 }
コード例 #14
0
        public async Task <ToDoListDTO> AddAsync(ToDoListDTO toDoListDTO)
        {
            var stringContent = new StringContent(JsonConvert.SerializeObject(toDoListDTO), Encoding.UTF8, "application/json");
            var response      = await _httpClient.PostAsync("todolist", stringContent);

            if (response.IsSuccessStatusCode)
            {
                toDoListDTO = JsonConvert.DeserializeObject <ToDoListDTO>(await response.Content.ReadAsStringAsync());
                return(toDoListDTO);
            }
            else
            {
                return(null);
            }
        }
コード例 #15
0
        public IActionResult UpdateToDoList([FromRoute] Guid id, [FromBody] ToDoListDTO toDoListDTO)
        {
            ToDoListDTO updatedDTO;

            try
            {
                updatedDTO = _service.UpdateToDoList(id, toDoListDTO, User.GetEmail());
            }
            catch (EntityNotFoundException)
            {
                return(NotFound());
            }

            return(Ok(updatedDTO));
        }
コード例 #16
0
        public void AddToDoList_ValidData()
        {
            var dto = new ToDoListDTO {
                Id = 11, Description = "Desc_11", LabelId = 1, CreatedBy = 1, UpdatedBy = 1, CreatedDate = DateTime.Now, UpdatedDate = DateTime.Now
            };
            var entity = new ToDoListEntity {
                Id = 11, Description = "Desc_11", LabelId = 1, CreatedBy = 1, UpdatedBy = 1, CreatedDate = DateTime.Now, UpdatedDate = DateTime.Now
            };

            _mapper.Setup(p => p.Map <ToDoListDTO, ToDoListEntity>(dto)).Returns(entity);
            _repo.Setup(p => p.Add(entity)).Returns(1);
            var returnObj = _toDoListService.AddToDoList(dto);

            Assert.AreEqual(11, returnObj.Id);
        }
コード例 #17
0
        public void UpdateToDoList(ToDoListDTO list, string owner)
        {
            ToDoList oldList = GetToDoList(list.Id, owner);

            if (oldList == null)
            {
                throw new EntityNotFoundException();
            }
            else if (oldList.Owner != owner)
            {
                throw new UnauthorizedException();
            }

            oldList.Update(list.ToEntity());
            _context.SaveChanges();
        }
コード例 #18
0
        public async Task <IActionResult> UdateToDoList(long id, ToDoListDTO toDoListDTO)
        {
            ApplicationUser user = await GetUser();

            if (user == null)
            {
                return(Unauthorized());
            }

            var toDoList = user.ToDoLists.SingleOrDefault(t => t.Id == id);

            if (id != toDoList.Id)
            {
                return(BadRequest());
            }

            if (toDoList == null)
            {
                return(NotFound());
            }

            toDoList.Name = toDoListDTO.Name;

            _context.Entry(toDoList).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ToDoListExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #19
0
        public ActionResult UpdateToDoList([FromBody] ToDoListDTO list)
        {
            _logger.LogInformation("ToDoList.UpdateToDoList() executed!");

            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            try
            {
                _service.UpdateToDoList(list, User.GetEmail());
                return(Ok());
            }
            catch (EntityNotFoundException)
            {
                return(NotFound());
            }
            catch (UnauthorizedException)
            {
                return(Unauthorized());
            }
        }
コード例 #20
0
        public async Task <ActionResult <ToDoListDTO> > CeateToDoList(ToDoListDTO toDoListDTO)
        {
            ApplicationUser user = await GetUser();

            if (user == null)
            {
                return(Unauthorized());
            }

            var toDoList = new ToDoList
            {
                Name   = toDoListDTO.Name,
                User   = user,
                UserId = user.Id
            };

            _context.ToDoLists.Add(toDoList);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(
                       nameof(GetToDoList),
                       new { id = toDoList.Id },
                       ListToDTO(toDoList)));
        }
コード例 #21
0
        public async Task <IActionResult> Update(ToDoListDTO toDoListDTO)
        {
            await _toDoListApiService.Update(toDoListDTO);

            return(RedirectToAction("Index"));
        }
コード例 #22
0
        public IActionResult CreateToDoList([FromBody] ToDoListDTO toDoListDTO)
        {
            ToDoListDTO newListDTO = _service.CreateToDoList(toDoListDTO, User.GetEmail());

            return(CreatedAtAction(nameof(GetToDoList), new { id = newListDTO.Id }, newListDTO));
        }
コード例 #23
0
 /// <summary>
 /// Adds to do list.
 /// </summary>
 /// <param name="item">The item.</param>
 /// <returns></returns>
 public ToDoListDTO AddToDoList(ToDoListDTO item)
 {
     return(_todoListService.AddToDoList(item));
 }
コード例 #24
0
 /// <summary>
 /// Updates to do list.
 /// </summary>
 /// <param name="item">The item.</param>
 /// <returns></returns>
 public ToDoListDTO UpdateToDoList(ToDoListDTO item)
 {
     return(_todoListService.UpdateToDoList(item));
 }
コード例 #25
0
 public ActionResult <ToDoListDTO> UpdateToDoList(ToDoListDTO todolist)
 {
     todolist.UpdatedBy = (long)HttpContext.Request.HttpContext.Items["Userid"];
     _toDoListService.UpdateToDoList(todolist);
     return(StatusCode((int)HttpStatusCode.OK, todolist));
 }
コード例 #26
0
        public async Task <IActionResult> Save(ToDoListDTO toDoListDTO)
        {
            var newToDoList = await _toDoListService.AddAsync(_mapper.Map <ToDoList>(toDoListDTO));

            return(Created(string.Empty, _mapper.Map <ToDoList>(newToDoList)));
        }
コード例 #27
0
        public IActionResult Update(ToDoListDTO toDoListDTO)
        {
            var toDoList = _toDoListService.Update(_mapper.Map <ToDoList>(toDoListDTO));

            return(NoContent());
        }