Пример #1
0
 public IActionResult Post([FromBody] User entity)
 {
     try
     {
         Console.WriteLine("POST");
         entity.Password = GetHash(sha256, entity.Password);
         var hasData = _dbContext.User.Where(user => (user.Account == entity.Account && user.Password == entity.Password)).ToList();
         if (hasData.Count == 0)
         {
             _dbContext.User.Add(entity);
             _dbContext.SaveChanges();
             return(Get(entity.Id));
         }
         else
         {
             ErrorModel error = new ErrorModel();
             error.Message = "Sign Up Failed.";
             return(new JsonResult(error));
         }
     }
     catch (Exception e)
     {
         TextWriter errorWriter = Console.Error;
         errorWriter.WriteLine(e.Message);
         return(BadRequest());
     }
 }
Пример #2
0
 public IActionResult Post([FromBody] Note entity)
 {
     try
     {
         Console.WriteLine(entity);
         _dbContext.Note.Add(entity);
         _dbContext.SaveChanges();
         Console.WriteLine(entity);
         return(Get(entity.Id));
     }
     catch (Exception e)
     {
         TextWriter errorWriter = Console.Error;
         errorWriter.WriteLine(e.Message);
         return(BadRequest());
     }
 }