Beispiel #1
0
 public ActionResult CreateHumanType(HumanTypeViewModel humanTypeViewModel)
 {
     if (!ModelState.IsValid)
     {
         return(View(humanTypeViewModel));
     }
     else
     {
         HumanType humanType    = new HumanType();
         var       humanLikings = new List <HumanTypeLiking>();
         humanType.HumanTypeName     = humanTypeViewModel.HumanTypeName;
         humanType.color             = humanTypeViewModel.color;
         humanType.numberOfLocations = humanTypeViewModel.NumberOfLocations;
         string[] likings       = humanTypeViewModel.HumanLikings.Split(' ');
         int[]    probabilities = humanTypeViewModel.probabilities.Split(' ').Select(int.Parse).ToArray();
         if (likings.Length == probabilities.Length)
         {
             for (int i = 0; i < likings.Length; i++)
             {
                 humanLikings.Add(new HumanTypeLiking {
                     humanTypeLikingName = likings[i],
                     probability         = probabilities[i]
                 });
             }
             humanType.humanLikings = humanLikings;
             context.humanTypes.AddOrUpdate(humanType);
             context.SaveChanges();
         }
         else
         {
             return(View(humanTypeViewModel));
         }
     }
     return(RedirectToAction("Index"));
 }
Beispiel #2
0
        public ActionResult CreateHumanType()
        {
            HumanTypeViewModel humanTypeViewModel = new HumanTypeViewModel();

            return(View(humanTypeViewModel));
        }