public ActionResult Index2(CreationModel model) { return(new ObjectResult(new { IsValid = ModelState.IsValid, Model = model })); }
public static User GetUser(this CreationModel model) { return(new User() { FirstName = model.FirstName, LastName = model.LastName, PhoneNumber = model.TelephoneNumber, UserName = model.Name, Email = model.Email }); }
public BaseModel ParseTokens(IList <string> tokens) { tokens.RemoveAt(0); var result = new CreationModel { Properties = new Dictionary <string, string>() }; var entityNameParsed = false; while (tokens.Count > 0) { var token = tokens[0]; if (!entityNameParsed) { if (Regex.IsMatch(token, Constants.EntityNamePattern)) { result.EntityName = token; entityNameParsed = true; } else { throw new ParsingException(); } } else { if (Regex.IsMatch(token, Constants.EntityDesignPattern)) { var split = token.Split(':'); var propertyName = split[0]; var propertyType = split[1]; if (Enum.TryParse(propertyType, true, out TypeNames _)) { result.Properties.Add(propertyName, propertyType.ToLower()); } else { throw new UnsupportedTypeException(propertyType); } } else { throw new ParsingException(); } } tokens.RemoveAt(0); } return(result); }
public async Task <ActionResult> Create(CreationModel model) { if (!ModelState.IsValid) { AddErrorsFromResult(new [] { "Something goes wrong - model is invalid, try reloading page" }); } try { await Manager.TryCreateUser(model); return(View("Succeded", (object)"Create was successfull")); } catch (ResultException resultException) { AddErrorsFromResult(resultException.ResultErrors); } return(View(model)); }
public async Task TryCreateUser(CreationModel userModel) { await TryCreateUser(userModel.GetUser(), userModel.Password); }