コード例 #1
0
 public ActionResult Index2(CreationModel model)
 {
     return(new ObjectResult(new
     {
         IsValid = ModelState.IsValid,
         Model = model
     }));
 }
コード例 #2
0
 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
     });
 }
コード例 #3
0
ファイル: CreationalParser.cs プロジェクト: ciker/Redis.SQL
        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);
        }
コード例 #4
0
        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));
        }
コード例 #5
0
 public async Task TryCreateUser(CreationModel userModel)
 {
     await TryCreateUser(userModel.GetUser(), userModel.Password);
 }