예제 #1
0
 public IHttpActionResult GetByUserUsername(string username)
 {
     using (DatabaseContext dbContext = new DatabaseContext())
     {
         try
         {
             var entity = dbContext.Users.Include(item => item.ImageInfos).Single(item => item.Username == username);
             var user   = new UserFE()
             {
                 Id            = entity.Id,
                 GroupId       = entity.GroupId,
                 Username      = entity.Username,
                 Password      = entity.Password,
                 IsDoctor      = entity.IsDoctor,
                 PersonGroupId = entity.PersonGroupId,
                 PersonId      = entity.PersonId
             };
             return(Ok(user));
         }
         catch (InvalidOperationException)
         {
             return(NotFound());
         }
         catch (Exception e)
         {
             return(InternalServerError(e));
         }
     }
 }
예제 #2
0
 public IHttpActionResult LoginUser([FromBody] LoginRequest request)
 {
     using (DatabaseContext dbContext = new DatabaseContext())
     {
         try
         {
             var entity = dbContext.Users.Include(item => item.ImageInfos)
                          .Single(u => u.Username == request.Username);
             if (Crypto.ComparePasswords(entity.Password, request.Password))
             {
                 var user = new UserFE()
                 {
                     Id            = entity.Id,
                     GroupId       = entity.GroupId,
                     Username      = entity.Username,
                     Password      = entity.Password,
                     IsDoctor      = entity.IsDoctor,
                     PersonGroupId = entity.PersonGroupId,
                     PersonId      = entity.PersonId
                 };
                 return(Ok(user));
             }
             else
             {
                 return(BadRequest());
             }
         }
         catch (InvalidOperationException)
         {
             return(NotFound());
         }
         catch (Exception e)
         {
             return(InternalServerError(e));
         }
     }
 }