public ActionResult CheckinGuests(int Id, int[] CheckinPeople)
 {
     if (CheckinPeople == null || CheckinPeople.Length == 0)
     {
         return Search(Id.ToString());
     }
     var viewModel = new GuestCheckinViewModel();
     viewModel.Id = Id;
     viewModel.PersonIdList = CheckinPeople;
     return View("AddGuest", viewModel);
 }
 public ActionResult AddCheckinGuest(int Id, int[] CheckinPeople, Person Person, HttpPostedFileBase picture, String canvasPicture)
 {
     PoolDataEntitiesConnection ctx = new PoolDataEntitiesConnection();
     var refPersonId = CheckinPeople[0];
     var refPerson = ctx.People.Single(p => p.Id == refPersonId);
     if(!Person.Is_Guest.HasValue){
         Person.Is_Guest = true;
     }
     Person.Family = refPerson.Family;
     var peopleList = CheckinPeople.ToList();
     if (picture != null && picture.ContentLength > 0)
     {
         try{
             var img = Image.FromStream(picture.InputStream);
             if (img.Height > 200 || img.Width > 200)
             {
                 Size size = new Size();
                 if(img.Size.Height > img.Size.Width){
                     size.Height = 200;
                     size.Width = (int)(img.Size.Width * (200.0 / img.Size.Height));
                 }else{
                     size.Width = 200;
                     size.Height = (int)(img.Size.Height * (200.0 / img.Size.Width));
                 }
                 img = new Bitmap(img, size);
             }
             var ms = new System.IO.MemoryStream();
             img.Save(ms,System.Drawing.Imaging.ImageFormat.Jpeg);
             Person.Picture = ms.ToArray();
         }catch(Exception e){
             ModelState.AddModelError("Person.Picture","Unknown error with image " + e.Message);
         }
     }
     else if (canvasPicture != null && canvasPicture.Length != 0)
     {
         try
         {
             var picBytes = Convert.FromBase64String(canvasPicture.Substring(canvasPicture.IndexOf("base64,") + 7));
             var memoryStream = new System.IO.MemoryStream(picBytes);
             //create image in order to convert to jpeg
             var img = Image.FromStream(memoryStream);
             var ms = new System.IO.MemoryStream();
             img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
             Person.Picture = ms.ToArray();
         }
         catch (Exception e)
         {
             ModelState.AddModelError("Picture", "Unknown error with image: " + e.Message);
         }
     }
     var viewModel = new GuestCheckinViewModel();
     if (ModelState.IsValid)
     {
         ctx.People.Add(Person);
         ctx.SaveChanges();
         peopleList.Add(Person.Id);
         viewModel.PersonIdList = peopleList.ToArray();
         viewModel.Person = new Person();
         TempData["success"] = "Added new guest";
         ModelState.Clear();
     }
     else
     {
         viewModel.PersonIdList = CheckinPeople;
         viewModel.Person = Person;
     }
     viewModel.Id = Id;
     if (ModelState.IsValid && Request.Form.AllKeys.Contains("checkin"))
     {
         return Checkin(Id, viewModel.PersonIdList);
     }else{
         return View("AddGuest", viewModel);
     }
 }