コード例 #1
0
        public ActionResult Politician(HttpPostedFileBase mainPic, HttpPostedFileBase listButtonPic, HttpPostedFileBase smallButtonPic, PersonDto personDto)
        {
            var    personRepo        = new PersonRepository();
            var    languageManager   = new LanguageManager();
            var    parliamentManager = new ParliamentManager();
            Person person;

            if (personDto.Id == 0)
            {
                if (personDto.GenericName.Trim() == personDto.GenericPost.Trim())
                {
                    TempData["Notifications"] = $"Please select different strings for post and name.";
                    return(View("Politician", personDto));
                }

                if (LanguageHelper.IsInUse(personDto.GenericName))
                {
                    TempData["Notifications"] = $"Name {personDto.GenericName} is already used in dictionary. Please select another one.";
                    return(View("Politician", personDto));
                }

                if (LanguageHelper.IsInUse(personDto.GenericPost))
                {
                    TempData["Notifications"] = $"Post {personDto.GenericPost} is already used in dictionary. Please select another one.";
                    return(View("Politician", personDto));
                }

                person = new Person();
                var firstPersonInList = personRepo.GetAll().OrderByDescending(p => p.Id).FirstOrDefault();
                if (firstPersonInList == null)
                {
                    personDto.Id = 1;
                }
                else
                {
                    personDto.Id = firstPersonInList.Id + 1;
                }

                TempData["Notifications"] = "Added new politician...";
            }
            else
            {
                person = personRepo.Get(personDto.Id);
                TempData["Notifications"] = "Saved...";
            }

            parliamentManager.FillImages(mainPic, listButtonPic, smallButtonPic, personDto, person);

            personDto.Tracks = person.Tracks;
            var updatedPerson = PersonMapper.MapPersonDto(personDto);

            languageManager.SaveTranslations(personDto);
            personRepo.Upsert(updatedPerson);

            return(RedirectToAction("Politician", new { id = personDto.Id }));
        }