Пример #1
0
 /// <summary>
 /// Method to insert/save User record
 /// </summary>
 /// <param name="user">User records to be inserted/saved</param>
 /// <returns></returns>
 public HttpResponseMessage Post(UserInputDTO userInputDto)
 {
     if (true)//TODO: replace this with validation logic ModelState.IsValid
     {
         var user = Mapper.Map<User>(userInputDto);
         _userService.Add(user);
         HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, user);
         response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = user.Id }));
         return response;
     }
     else
     {
         return Request.CreateResponse(HttpStatusCode.BadRequest);
     }
 }
Пример #2
0
 /// <summary>
 /// Method to update user
 /// </summary>
 /// <param name="user">Users record to be updated</param>
 /// <returns></returns>
 public IHttpActionResult Put(UserInputDTO value)
 {
     if (true)//TODO: replace this with validation logic ModelState.IsValid
     {
         var searchedUser = _userService.FindBy(t => t.Id == value.Id);
         if (value == null)
         {
             return BadRequest("Cannot update user/ user not found");
         }
         var toBeUpdatedRecord = Mapper.Map<User>(value);
         _userService.Update(searchedUser);
         return Ok();
     }
     else
     {
         return BadRequest();
     }
 }