public ActionResult Create(ApplicationCV applicationcv)
        {
            applicationcv.UserName = HttpContext.User.Identity.Name;
            if (ModelState.IsValid)
            {
                //Stupid ASP
                if (HttpContext.Request.Form.Get("gender") == "Male")
                    applicationcv.Gender = true;
                else
                    applicationcv.Gender = false;

                db.ApplicationCVs.Add(applicationcv);
                db.SaveChanges();

                return RedirectToAction("EditCreate", new {hasSent=true});
            }

            return View(applicationcv);
        }
        public static ReturnedThing GetResults(List<PairAccountsValue> values, List<int> groups, List<ApplicationCV> acceptedPeople)
        {
            List<List<ApplicationCV>> results = new List<List<ApplicationCV>>();

            int nGroup = 0;

            while (nGroup < groups.Count && groups[nGroup] <= acceptedPeople.Count)
            {
                List<ApplicationCV> local = new List<ApplicationCV>();

                //if we have only one person... select the first one
                if (groups[nGroup] == 1)
                {
                    local.Add(acceptedPeople[0]);
                    acceptedPeople.RemoveAt(0);
                    results.Add(local);
                    break;
                }

                //select starting group (it was not selected)

                foreach (var i in values)
                {
                    if (acceptedPeople.Contains(i.First) && acceptedPeople.Contains(i.Second))
                    {
                        local.Add(i.First);
                        local.Add(i.Second);
                        acceptedPeople.Remove(i.First);
                        acceptedPeople.Remove(i.Second);

                        //acceptedPeople.RemoveAll(r => r.UserName == values[0].First.UserName);
                        //acceptedPeople.RemoveAll(r => r.UserName == values[0].Second.UserName);
                        break;
                    }
                }

                //search for other people to enter the group
                while (groups[nGroup] > local.Count)
                {
                    int max = -1;
                    ApplicationCV best = new ApplicationCV();

                    foreach (var candidate in acceptedPeople)
                    {
                        //test candidate if it has the best chances
                        int localsum = 0;
                        foreach (var member in local)
                        {
                            //search local thing
                            List<PairAccountsValue> pair = values.Where(r=> (r.First.UserName==member.UserName && r.Second.UserName==candidate.UserName) || (r.Second.UserName==member.UserName && r.First.UserName==candidate.UserName)).ToList();
                            if (pair.Count == 1)
                            {
                                localsum += pair[0].Value;
                            }
                        }
                        if (localsum > max)
                        {
                            max = localsum;
                            best = candidate;
                        }
                    }

                    local.Add(best);
                    acceptedPeople.Remove(best);
                }
                results.Add(local);
                ++nGroup;
            }

            ReturnedThing returned = new ReturnedThing();
            returned.Groups = results;
            returned.Outside = acceptedPeople;
            return returned;
        }
        public ActionResult Editor(string UserName, string Id, ApplicationCV applicationcv)
        {
            //applicationcv.UserName = HttpContext.User.Identity.Name;
            applicationcv.WhoConfirmedIt = HttpContext.User.Identity.Name;
            applicationcv.HasBeenVerified = true;
            applicationcv.UserName = UserName;
            applicationcv.Id = int.Parse(Id);

            if (ModelState.IsValid)
            {
                db.Entry(applicationcv).State = EntityState.Modified;
                db.SaveChanges();

                ApplicationCV next = db.ApplicationCVs.FirstOrDefault(r => r.Id > applicationcv.Id && r.HasBeenVerified == false);
                if (next != null)
                    ViewBag.Next = next.Id;

                ViewBag.Message = "The operation has suceeded.";
                return View(applicationcv);
            }

            ViewBag.Message = "There has been an error.";
            return View(applicationcv);
        }
        public ActionResult Edit(ApplicationCV applicationcv)
        {
            if (1 == 1) //TO DO: Add validation
            {
                applicationcv.UserName = HttpContext.User.Identity.Name;

                if (ModelState.IsValid)
                {
                    //Stupid ASP
                    if (HttpContext.Request.Form.Get("gender") == "Male")
                        applicationcv.Gender = true;
                    else
                        applicationcv.Gender = false;

                    db.Entry(applicationcv).State = EntityState.Modified;
                    db.SaveChanges();
                    ViewBag.Message = "You have succesfully sent your CV.";
                    return View(applicationcv);
                }
                ViewBag.Message = "You have an error.";
                return View(applicationcv);
            }
        }