コード例 #1
0
ファイル: Fill.cs プロジェクト: sdluhaibing/ProDinner
        protected override void Inject(object target)
        {
            var props = target.GetType().GetProps();

            foreach (var p in props)
            {
                if (p.PropertyType == typeof(string))
                {
                    p.SetValue(target, "a" + ++s);
                }
                else if (p.PropertyType == typeof(int) && !p.Name.EndsWith("Id"))
                {
                    p.SetValue(target, ++i);
                }
                else if (p.PropertyType == typeof(DateTime))
                {
                    p.SetValue(target, DateTime.Now);
                }
                else if (p.PropertyType.IsSubclassOf(typeof(Entity)))
                {
                    Console.WriteLine("   create a " + p.PropertyType.Name);
                    dynamic o = Activator.CreateInstance(p.PropertyType).InjectFrom(new Fill(urepo, true));
                    o = urepo.Insert(o);
                    urepo.Save();
                    p.SetValue(target, o);
                }
                else if (p.PropertyType.IsGenericType && p.PropertyType.GetGenericTypeDefinition() == typeof(ICollection <>) && !isChild)
                {
                    var t = p.PropertyType.GetGenericArguments()[0];
                    if (!t.IsSubclassOf(typeof(DelEntity)))
                    {
                        continue;
                    }

                    var     tlist = typeof(List <>).MakeGenericType(t);
                    dynamic list  = Activator.CreateInstance(tlist);
                    Console.WriteLine("   creating a list of " + t.Name);
                    for (var k = 0; k < 3; k++)
                    {
                        Console.WriteLine("      create a " + t.Name);
                        dynamic o = Activator.CreateInstance(t).InjectFrom(new Fill(urepo, true));
                        o = urepo.Insert(o);
                        urepo.Save();
                        Console.WriteLine("      add " + t.Name + " to list");
                        list.Add(o);
                    }

                    p.SetValue(target, list);
                }
            }
        }
コード例 #2
0
        protected override void Inject(object target)
        {
            var props = target.GetProps();

            for (var j = 0; j < props.Count; j++)
            {
                var p = props[j];
                if (p.PropertyType == typeof(string))
                {
                    p.SetValue(target, "a" + ++s);
                }
                else if (p.PropertyType == typeof(int) && !p.Name.EndsWith("Id"))
                {
                    p.SetValue(target, ++i);
                }
                else if (p.PropertyType == typeof(DateTime))
                {
                    p.SetValue(target, DateTime.Now);
                }
                else if (p.PropertyType.IsSubclassOf(typeof(DelEntity)))
                {
                    dynamic o = Activator.CreateInstance(p.PropertyType).InjectFrom(new Fill(u, true));
                    u.Insert(o);
                    u.Save();
                    p.SetValue(target, o);
                }
                else if (p.PropertyType.IsGenericType && p.PropertyType.GetGenericTypeDefinition() == typeof(ICollection <>) && !isChild)
                {
                    var t = p.PropertyType.GetGenericArguments()[0];
                    if (!t.IsSubclassOf(typeof(DelEntity)))
                    {
                        continue;
                    }

                    var     tlist = typeof(List <>).MakeGenericType(t);
                    dynamic list  = Activator.CreateInstance(tlist);
                    for (var k = 0; k < 3; k++)
                    {
                        dynamic o = Activator.CreateInstance(t).InjectFrom(new Fill(u, true));
                        u.Insert(o);
                        u.Save();
                        list.Add(o);
                    }
                    p.SetValue(target, list);
                }
            }
        }
コード例 #3
0
        public ActionResult Create(FeedbackInput input)
        {
            if (!ModelState.IsValid)
            {
                return(PartialView(input));
            }

            input.Comments = HtmlUtil.SanitizeHtml(input.Comments);

            var feedback = new Feedback {
                Comments = input.Comments
            };

            feedback = repo.Add(feedback);
            repo.Save();

            Session["lastFeedback"] = feedback.Id;
            return(Json(new { }));
        }