public HttpResponseMessage Get(string appName) { HttpResponseMessage response = new HttpResponseMessage(); try { using (BookingCarEntities db = new BookingCarEntities()) { var version = db.Version.Where(x => x.AppName == appName).OrderByDescending(x => x.VerCode).FirstOrDefault(); if (version != null) { response = Request.CreateResponse(HttpStatusCode.OK, new { Success = true, Data = version }); } else { response = Request.CreateResponse(HttpStatusCode.OK, new { Success = false, Data = "找不到此APP相關資訊" }); } } } catch (Exception ex) { _logger.Error("發生錯誤:{0}", ex.Message); response = Request.CreateResponse(HttpStatusCode.InternalServerError, new { Success = false, Message = "發生錯誤" }); } return(response); }
// GET api/login public UserLoginInfo Get(string account, string password) { UserLoginInfo viewModel = new UserLoginInfo(); try { _logger.Debug("start"); _logger.Debug("param: account:{0}", account); using (BookingCarEntities db = new BookingCarEntities()) { var user = db.Users.Where(x => x.Account == account).FirstOrDefault(); if (user != null) { if (user.PasswordHash == password) { viewModel.Account = user.Account; viewModel.Name = user.Name; viewModel.IsLoginValid = true; //viewModel.FacID = "未知"; //viewModel.UserTitle = user.UserTitle; } else { viewModel.ErrorMessage = "密碼錯誤"; } } else { viewModel.ErrorMessage = string.Format("使用者:{0}不存在", account); } } } catch (Exception ex) { viewModel.ErrorMessage = ex.Message; _logger.Error("發生錯誤:{0}", ex.Message); } finally { _logger.Debug("end"); } return(viewModel); }