Ejemplo n.º 1
0
        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 SetValsToProps(urepo, true));
                    o = urepo.Add(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 SetValsToProps(urepo, true));
                        o = urepo.Add(o);
                        urepo.Save();
                        Console.WriteLine("      add " + t.Name + " to list");
                        list.Add(o);
                    }

                    p.SetValue(target, list);
                }
            }
        }
Ejemplo n.º 2
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 { }));
        }