public ActionResult CreateNewRepresentative(Representative representative)
        {
            if (Session["OrganisationID"] == null)
            {
                TempData["accessError"] = "Vaše session vypršela, nebo nejste přihlášen.";
                return RedirectToAction("LogOn", "Organisation");
            }

            try
            {
                if (ModelState.IsValid)
                {
                    string encryptPass = SHA512Manager.EncryptSHA512(representative.Password);
                    representative.Active = false;
                    representative.Password = encryptPass;
                    representative.ConfirmPassword = encryptPass;

                    var foundRepresentative = db.RepresentativesESG.Where(r => r.CompanyID == representative.CompanyID && r.Password == encryptPass).SingleOrDefault();

                    if (foundRepresentative != null)
                    {
                        representative.Password = "";
                        representative.ConfirmPassword = "";
                        ViewData["samePassError"] = "V systému se již nachází zástupce této organizace se stejným heslem.";
                        return View(representative);
                    }

                    db.RepresentativesESG.Add(representative);
                    db.SaveChanges();

                    TempData["RepresentativeCreated"] = "Byl úspěšně vytvořen nový účet zástupce organizace.";
                    return RedirectToAction("CreateNewRepresentative");
                }
            }
            catch (DataException)
            {
                ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
            }
            return View(representative);
        }
        public ActionResult Registration(Organisation organisation)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var foundOrganisation = db.CompaniesESG.Where(o => o.Ico == organisation.Ico).SingleOrDefault();

                    if (foundOrganisation != null)
                    {
                        ViewData["sameIcoOrganisation"] = "V systému se již nachází organizace se stejným IČO.";
                        ViewData["logOnView"] = "logOnView";
                        PopulateSectorsDropDownList(organisation.SectorID);
                        return View(organisation);
                    }

                    foundOrganisation = db.CompaniesESG.Where(o => o.Dic == organisation.Dic).SingleOrDefault();

                    if (foundOrganisation != null)
                    {
                        ViewData["sameDicOrganisation"] = "V systému se již nachází organizace se stejným DIČ.";
                        ViewData["logOnView"] = "logOnView";
                        PopulateSectorsDropDownList(organisation.SectorID);
                        return View(organisation);
                    }

                    string encryptPassword = SHA512Manager.EncryptSHA512(organisation.Password);

                    Company company = new Company();
                    company.Address = organisation.Address;
                    company.Created = DateTime.Now;
                    company.Description = organisation.Description;
                    company.Dic = organisation.Dic.ToUpper();
                    company.Email = organisation.Email;
                    company.Ico = organisation.Ico;
                    company.Name = organisation.Name;
                    company.SectorID = organisation.SectorID;
                    company.Telephone = organisation.Telephone;
                    company.Webpage = organisation.Webpage;

                    db.CompaniesESG.Add(company);

                    db.SaveChanges();

                    Representative representative = new Representative();

                    representative.Degree = organisation.Degree;
                    representative.Firstname = organisation.Firstname;
                    representative.IdNumber = organisation.IdNumber;
                    representative.CompanyID = company.ID;
                    representative.Password = encryptPassword;
                    representative.ConfirmPassword = encryptPassword;
                    representative.PersonalEmail = organisation.PersonalEmail;
                    representative.PersonalTelephone = organisation.PersonalTelephone;
                    representative.Surname = organisation.Surname;
                    representative.Active = true;

                    db.RepresentativesESG.Add(representative);

                    db.SaveChanges();

                    XBRLTransformer.CreateTaxonomy(company.ID);

                    Session["OrganisationID"] = company.ID;
                    Session["RepresentativeID"] = representative.ID;
                    Session["OrganisationName"] = company.Name;

                    return RedirectToAction("Index", "Home");
                }

            }
            catch (System.Data.DataException)
            {
                //Log the error (add a variable name after DataException)
                ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
            }

            PopulateSectorsDropDownList(organisation.SectorID);
            ViewData["logOnView"] = "logOnView";
            return View(organisation);
        }