public IHttpActionResult PuttUserLogin(int id, tUserLogin tUserLogin) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != tUserLogin.LoginID) { return(BadRequest()); } db.Entry(tUserLogin).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!tUserLoginExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PosttUserLogin(tUserLogin tUserLogin) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.tUserLogins.Add(tUserLogin); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = tUserLogin.LoginID }, tUserLogin)); }
private LoginResult GetLoginResult(tUserLogin d) { return(new LoginResult { DeviceID = d.DeviceID, Token = d.Token, User = new MiniProfile { UserName = d.UserName } }); }
public async Task <ObjectResult <LoginResult> > LoginAsync(LoginContract user) { ObjectResult <LoginResult> result = new ObjectResult <LoginResult>(); try { string _password = HelperMethod.encrypt(user.Password); var query = userRepository.GetTable.Where(d => d.Username.Equals(user.Username) && d.Password.Equals(_password)).AsQueryable(); var data = await userRepository.GetDataAsync(query); if (data != null) { ServiceResult loginResult = new ServiceResult(); loginResult.OK(); var loginQuery = userLoginRepository.GetTable.Where(d => d.UserName.Equals(user.Username) && d.DeviceID.Equals(user.DeviceID)).AsQueryable(); if (await userLoginRepository.GetCountAsync(loginQuery) == 0) { tUserLogin _loginData = new tUserLogin { UserLoginID = HelperMethod.GenerateID(), UserName = user.Username, DeviceID = user.DeviceID, Token = HelperMethod.GenerateID().ToString() }; var saveLogin = await userLoginRepository.AddAsync(_loginData); loginResult = saveLogin.status; } if (loginResult.succeeded) { var loginData = await userLoginRepository.GetDataAsync(loginQuery); result.obj = GetLoginResult(loginData); result.status.OK(); } else { result.status = loginResult; } } else { result.status.NotFound("Data Not Found"); } } catch (Exception ex) { result.status.Error("Error", ex.Message); } return(result); }
public IHttpActionResult DeletetUserLogin(int id) { tUserLogin tUserLogin = db.tUserLogins.Find(id); if (tUserLogin == null) { return(NotFound()); } db.tUserLogins.Remove(tUserLogin); db.SaveChanges(); return(Ok(tUserLogin)); }
public async Task <ServiceResult> LogoutAsync(LogoutContract user) { ServiceResult result = new ServiceResult(); try { tUserLogin data = await userLoginRepository.GetDataAsync(userLoginRepository.GetTable.Where(d => d.Token.Equals(user.Token) && d.DeviceID.Equals(user.DeviceID)).AsQueryable()); if (data != null) { result = await userLoginRepository.RemoveAsync(data); } else { result.NotFound("Data Not Found"); } } catch (Exception ex) { result.Error("Error", ex.Message); } return(result); }