Esempio n. 1
0
        public ActionResult AdminRegister(RegisterAdminAndCompanyViewModel model)
        {
            ViewBag.Countries = _countryService.GetAll();
            if (ModelState.IsValid)
            {
                try
                {
                    if (model.Password != model.RePassword)
                    {
                        ViewBag.Message = "Şifreler uyuşmuyor";
                        return(View("AdminRegister"));
                    }
                    else
                    {
                        Company company = new Company();
                        company.About       = model.About;
                        company.CompanyName = model.CompanyName;
                        company.Freight     = model.Freight;
                        company.LogoPath    = model.LogoPath;
                        company.TaxNumber   = model.TaxNumber;
                        company.Phone       = model.Phone;
                        bool resultCompany = _companyService.Add(company);
                        if (!resultCompany)
                        {
                            ViewBag.Message = "Şirket eklemede hata meydana geldi!";
                        }

                        Admin admin = new Admin();
                        admin.AdminRole = _adminRoleService.GetAdminRoleByName("Company Admin");
                        admin.EMail     = model.EMail;
                        admin.Password  = model.Password;
                        admin.Username  = model.Username;
                        admin.Company   = company;
                        bool resultAdmin = _adminService.Add(admin);
                        if (!resultAdmin)
                        {
                            ViewBag.Message = "Şirket eklemede hata meydana geldi!";
                        }

                        return(RedirectToAction("AdminLogin", "Login"));
                    }
                }
                catch (Exception ex)
                {
                    ViewBag.Message = ex.Message;
                    return(View("AdminRegister"));
                }
            }
            else
            {
                return(View());
            }
        }