public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            People people = db.Peoples.Include(p => p.PeopleInfo).Include(p => p.Proffesion).Where(p => p.PeopleID == id).Single();

            if (people == null)
            {
                return(HttpNotFound());
            }

            PeopleFormView peopleFormView = new PeopleFormView
            {
                FirstName  = people.FirstName,
                LastName   = people.LastName,
                Proffesion = people.Proffesion,
                Birthdate  = people.Birthdate,

                Biography  = people.PeopleInfo.Biography,
                Birthplace = people.PeopleInfo.Birthplace,
                Height     = people.PeopleInfo.Height,
                RowVersion = people.PeopleInfo.RowVersion,
            };

            ViewBag.Name     = people.FullName;
            ViewBag.PeopleID = id;
            return(View(peopleFormView));
        }
        public ActionResult Create()
        {
            PeopleFormView peopleFormView = new PeopleFormView();

            peopleFormView.PhotoURL  = String.Empty;
            peopleFormView.Birthdate = DateTime.Today;

            return(View(peopleFormView));
        }
        public ActionResult Create([Bind(Include = "FirstName,LastName,Birthdate,Birthplace,Height,Biography,Proffesion,PhotoURL")] PeopleFormView peopleFormView, string RadioPhotoBtn, string UrlPath, HttpPostedFileBase image)
        {
            //CheckBirthday(people.Birthdate);

            if (ModelState.IsValid)
            {
                People people = new People
                {
                    FirstName  = peopleFormView.FirstName,
                    LastName   = peopleFormView.LastName,
                    Proffesion = peopleFormView.Proffesion,
                    Birthdate  = peopleFormView.Birthdate,
                };

                people.PeopleInfo = new PeopleInfo
                {
                    Biography  = peopleFormView.Biography,
                    Birthplace = peopleFormView.Birthplace,
                    Height     = peopleFormView.Height,
                };


                if (!String.IsNullOrEmpty(RadioPhotoBtn))
                {
                    switch (RadioPhotoBtn)
                    {
                    case "FromFile":
                        if (image != null)
                        {
                            people.PhotoURL = SaveNewFile("PeopleFaces", people.FullName, image);
                        }
                        else
                        {
                            people.PhotoURL = IfEmptySetEmptyPhoto(people.PhotoURL);
                        }
                        break;

                    case "FromURL":
                        if (!String.IsNullOrEmpty(UrlPath))
                        {
                            DeleteOldFile(people.PhotoURL);
                            people.PhotoURL = UrlPath;
                        }
                        break;

                    case "None":
                        DeleteOldFile(people.PhotoURL);
                        people.PhotoURL = NoContentPhoto;
                        break;

                    default:
                        people.PhotoURL = IfEmptySetEmptyPhoto(people.PhotoURL);
                        break;
                    }
                }
                else
                {
                    people.PhotoURL = IfEmptySetEmptyPhoto(people.PhotoURL);
                }


                db.Peoples.Add(people);
                db.SaveChanges();
                TempData["Success"] = "Poprawnie dodano postać filmową.";
                return(RedirectToAction("Index"));
            }
            ViewData["Error"] = "Nie można zapisać, popraw błędy!";
            return(View(peopleFormView));
        }
        public ActionResult Edit(int?id, string RadioPhotoBtn, string UrlPath, HttpPostedFileBase image, byte[] rowVersion)
        {
            //[Bind(Include = "PeopleID,FirstName,LastName,Birthdate,Birthplace,Height,Biography,FacePhoto,FaceMimeType")] People people

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var people = db.Peoples.Include(p => p.PeopleInfo).Include(p => p.Proffesion).Where(p => p.PeopleID == id).Single();

            if (people == null)
            {
                return(HttpNotFound());
            }

            if (TryUpdateModel(people, "", new string[] { "FirstName", "LastName", "Birthdate", "Proffesion", "PhotoURL" }))
            {
                if (TryUpdateModel(people.PeopleInfo, "", new string[] { "Birthplace", "Height", "Biography", "RowVersion" }))
                {
                    try
                    {
                        if (ModelState.IsValid)
                        {
                            db.Entry(people.PeopleInfo).OriginalValues["RowVersion"] = rowVersion;

                            if (!String.IsNullOrEmpty(RadioPhotoBtn))
                            {
                                switch (RadioPhotoBtn)
                                {
                                case "FromFile":
                                    if (image != null)
                                    {
                                        people.PhotoURL = SaveNewFile("PeopleFaces", people.FullName, image);
                                    }
                                    else
                                    {
                                        people.PhotoURL = IfEmptySetEmptyPhoto(people.PhotoURL);
                                    }
                                    break;

                                case "FromURL":
                                    if (!String.IsNullOrEmpty(UrlPath))
                                    {
                                        DeleteOldFile(people.PhotoURL);
                                        people.PhotoURL = UrlPath;
                                    }
                                    break;

                                case "None":
                                    DeleteOldFile(people.PhotoURL);
                                    people.PhotoURL = NoContentPhoto;
                                    break;

                                default:
                                    people.PhotoURL = IfEmptySetEmptyPhoto(people.PhotoURL);
                                    break;
                                }
                            }
                            else
                            {
                                people.PhotoURL = IfEmptySetEmptyPhoto(people.PhotoURL);
                            }

                            /*
                             * if (people.Proffesion.Actor == false && people.Proffesion.Director == false && people.Proffesion.Scenario == false)
                             * {
                             *  people.Proffesion = null;       //usuwa rekord w DB
                             * }
                             */
                            db.Entry(people).State = EntityState.Modified;
                            db.SaveChanges();
                            TempData["Success"] = "Poprawnie zmieniono informacje o człowieku.";
                            return(RedirectToAction("Details", "People", new { id = people.PeopleID }));
                        }
                    }
                    catch (DbUpdateConcurrencyException ex)
                    {
                        var PeopleInfo_DBEntry = ex.Entries.Single().GetDatabaseValues();

                        if (PeopleInfo_DBEntry == null)
                        {
                            ModelState.AddModelError(string.Empty, "Postać, którą próbujesz zmienić, została już usunięta.");
                        }
                        else
                        {
                            var PeopleInfo_DBValues = (PeopleInfo)PeopleInfo_DBEntry.ToObject();
                            var People_DBValues     = (People)db.Entry(people).GetDatabaseValues().ToObject();
                            var Proffesion_DBValues = (Proffesion)db.Entry(people.Proffesion).GetDatabaseValues().ToObject();

                            if (People_DBValues.FirstName != people.FirstName)
                            {
                                ModelState.AddModelError("FirstName", "Aktualna wartość: " + People_DBValues.FirstName);
                            }
                            if (People_DBValues.LastName != people.LastName)
                            {
                                ModelState.AddModelError("LastName", "Aktualna wartość: " + People_DBValues.LastName);
                            }
                            if (People_DBValues.Birthdate != people.Birthdate)
                            {
                                ModelState.AddModelError("Birthdate", "Aktualna wartość: " + People_DBValues.Birthdate.ToShortDateString());
                            }
                            if (People_DBValues.PhotoURL != people.PhotoURL)
                            {
                                ModelState.AddModelError(String.Empty, "Zmienione zostało zdjęcie główne");
                            }

                            if (!Proffesion_DBValues.EqualTo(people.Proffesion))
                            {
                                ModelState.AddModelError(String.Empty, "Zmieniony został zawód postaci");
                            }

                            if (PeopleInfo_DBValues.Birthplace != people.PeopleInfo.Birthplace)
                            {
                                ModelState.AddModelError("Birthplace", "Aktualna wartość: " + PeopleInfo_DBValues.Birthplace);
                            }
                            if (PeopleInfo_DBValues.Height != people.PeopleInfo.Height)
                            {
                                ModelState.AddModelError("Height", "Aktualna wartość: " + PeopleInfo_DBValues.Height);
                            }
                            if (PeopleInfo_DBValues.Biography != people.PeopleInfo.Biography)
                            {
                                ModelState.AddModelError("Biography", "Aktualna wartość:  " + PeopleInfo_DBValues.Biography);
                            }

                            ViewData["Error"]            = "Postać, którą próbujesz zmienić, została już zmieniona, jeśli nadal chcesz kontynuować, zapisz ponownie, lecz utracisz poprzednie dane.";
                            people.PeopleInfo.RowVersion = PeopleInfo_DBValues.RowVersion;
                        }
                    }
                    catch (RetryLimitExceededException)
                    {
                        ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator.");
                    }
                }
            }

            ViewBag.Name     = people.FullName;
            ViewBag.PeopleID = id;

            PeopleFormView peopleFormView = new PeopleFormView
            {
                FirstName  = people.FirstName,
                LastName   = people.LastName,
                Proffesion = people.Proffesion,
                Birthdate  = people.Birthdate,

                Biography  = people.PeopleInfo.Biography,
                Birthplace = people.PeopleInfo.Birthplace,
                Height     = people.PeopleInfo.Height,
                RowVersion = people.PeopleInfo.RowVersion,
            };

            if (String.IsNullOrEmpty(ViewData["Error"].ToString()))
            {
                ViewData["Error"] = "Nie można zapisać, popraw błędy!";
            }
            return(View(peopleFormView));
        }