public virtual async Task <IProcessorResult <T> > Create() { IProcessorResult <T> result; var v = Validate(); if (!v.Success) { return(new ProcessorResult <T>("Validation failed : " + v.Failures[0])); } try { var save = await _dataHelper.Save(); if (save != null) { result = new ProcessorResult <T>(save); } else { result = new ProcessorResult <T>("Save failed."); } } catch (Exception ex) { result = new ProcessorResult <T>(ex.Message); } return(result); }
public async Task <IProcessorResult <Guid> > Login() { IProcessorResult <Guid> result; try { var users = await DataHelper.FetchQuery(string.Format(@"(Username eq '{0}') and(Password eq '{1}')", Model.Username, Model.Password)); if (users.Count == 1) { IToken t = new Token(); t.Id = Guid.NewGuid(); t.UserId = users[0].Id; //Set up a token after login is successful var tp = new TokenProcessor(t); await tp.Create(); result = new ProcessorResult <Guid>(t.Id); } else { result = new ProcessorResult <Guid>("No user found."); } } catch (Exception ex) { result = new ProcessorResult <Guid>(ex.Message); } return(result); }
public async override Task <IProcessorResult <IUser> > Create() { var users = await GetUserByUsername(); if (users.Count > 0) { IProcessorResult <IUser> result = new ProcessorResult <IUser>("Username already exists."); return(result); } return(await base.Create()); }
public virtual async Task <IProcessorResult <T> > FetchById() { IProcessorResult <T> result; try { var fetch = await _dataHelper.FetchById(); Model = fetch; result = new ProcessorResult <T>(fetch); } catch (Exception ex) { result = new ProcessorResult <T>(ex.Message); } return(result); }