public async Task<LoginProperty> UpdateAsync(LoginProperty loginProperty) { if (loginProperty == null) throw new ArgumentNullException("loginProperty"); LoginProperty _prop = await FindByNameAsync(loginProperty.LoginId,loginProperty.PropertyName); if(_prop==null) { loginProperty.Id = Guid.NewGuid(); await Task.Factory.StartNew(() => { IDbConnection connection = CurrentContext.OpenConnection(CurrentContext.CurrentTransaction); connection.Execute("INSERT INTO auth_LoginProperties(Id, LoginId, PropertyName, PropertyValue) VALUES(@Id, @LoginId, @PropertyName, @PropertyValue)", new { Id=loginProperty.Id, LoginId=loginProperty.LoginId, PropertyName=loginProperty.PropertyName, PropertyValue=loginProperty.PropertyValue }, CurrentContext.CurrentTransaction); }); } else { loginProperty.Id=_prop.Id; await Task.Factory.StartNew(() => { IDbConnection connection = CurrentContext.OpenConnection(CurrentContext.CurrentTransaction); connection.Execute("Update auth_LoginProperties SET PropertyName=@PropertyName, PropertyValue=@PropertyValue WHERE Id=PropertyId", new { PropertyName=loginProperty.PropertyName, PropertyValue=loginProperty.PropertyValue, PropertyId=_prop.Id }, CurrentContext.CurrentTransaction); }); } return loginProperty; }
public async Task<HttpResponseMessage> Post([FromBody] LoginPropertyModel _property) { HttpResponseMessage _return = null; try { Login _login = await WorkManager.LoginManager.FindOpenByClientIdAsync(_property.SessionToken); if(_login!=null) { LoginProperty _loginProperty = new LoginProperty(); _loginProperty.LoginId = _login.Id; _loginProperty.PropertyName = _property.PropertyName; _loginProperty.PropertyValue = _property.PropertyValue; await WorkManager.LoginManager.UpdatePropertyAsync(_login, _loginProperty); _return = Request.CreateResponse<bool>(HttpStatusCode.OK, true); } else { _return = Request.CreateResponse<bool>(HttpStatusCode.Unauthorized, false); } } catch(Exception ex) { _return = Request.CreateResponse<bool>(HttpStatusCode.InternalServerError, false); } if (_return == null) { _return = Request.CreateResponse<bool>(HttpStatusCode.InternalServerError, false); } return _return; }