Esempio n. 1
0
        public static CompanyRegisterViewModel Dto(this CompanyRegister o)
        {
            var viewMode = new CompanyRegisterViewModel();

            ModelCopier.CopyModel(o, viewMode);
            viewMode.CompanyRegisterId = o.CompanyRegisterId;
            if (o.CorpBaseInfoId != null)
            {
                viewMode.CorpBaseInfoId   = o.CorpBaseInfoId;
                viewMode.CorpBaseInfoName = o.CorpBaseInfoName;
            }
            else
            {
                viewMode.CorpBaseInfoId   = o.CorpBaseInfoId;
                viewMode.CorpBaseInfoName = o.CorpBaseInfoOther;
            }
            viewMode.SN                 = o.SN;
            viewMode.Creator            = o.Creator;
            viewMode.CreatorDisplayName = o.StartUser.DisplayName;
            viewMode.CreatedTime        = o.CreatedTime.ToString("yyyy-MM-dd");
            viewMode.ModifyName         = o.Creator;
            viewMode.ModifyDisplayName  = o.StartUser.DisplayName;
            viewMode.ModifyTime         = o.ModifyTime.ToString("yyyy-MM-dd");
            IsoDateTimeConverter timeConverter = new IsoDateTimeConverter();

            //这里使用自定义日期格式,如果不使用的话,默认是ISO8601格式
            timeConverter.DateTimeFormat       = "yyyy'-'MM'-'dd";
            viewMode.CompanyRegisterRecordJson = JsonConvert.SerializeObject(o.CompanyRegisterRecords, timeConverter);
            return(viewMode);
        }
Esempio n. 2
0
        public ActionResult RegisterCompany(CompanyRegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var company = CompanyRepo.GetByName(model.Name);

                if (company != null)
                {
                    //company name has already an company in database, generate error and return to Register view
                    ModelState.AddModelError("", "Your chosen company name is already taken!\nMaybe this company already exists in the database.");
                    //save viewdata and return to view
                    TempData["ViewD"] = ViewData;
                    return(RedirectToAction("Register"));
                }

                //Company does not exist in database if code gets to here

                Company c = new Company()
                {
                    Name     = model.Name,
                    Location = model.Location,
                    Sector   = model.Sector,
                    Package  = model.Package
                };
                try
                {
                    CompanyRepo.Add(c);
                    CompanyRepo.SaveChanges();
                }
                catch (DbEntityValidationException dbEx)
                {
                    foreach (var validationErrors in dbEx.EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            ModelState.AddModelError(validationError.PropertyName, validationError.ErrorMessage);
                        }
                    }

                    //Something went wrong, consider Modelstate invalid and return values to Register View
                    //save model and return to register view
                    TempData["regMod"] = model;
                    TempData["ViewD"]  = ViewData;
                    return(RedirectToAction("Register"));
                }
            }
            else
            {
                //if modelstate is somehow invalid
                //save model and return to register view
                TempData["regMod"] = model;
                TempData["ViewD"]  = ViewData;
                return(RedirectToAction("Register"));
            }
            //TODO: return message that registration was succesful!
            return(RedirectToAction("EhvPanel", "Home"));
        }
Esempio n. 3
0
        public ActionResult Register()
        {
            CompanyRegisterViewModel model = null;

            if (TempData["ViewD"] != null)
            {
                //previous model submit attempt was invalid, return to Register page
                ViewData = (ViewDataDictionary)TempData["ViewD"];
                //if there was a RegisterViewModel saved in Tempdata, return Register view with previous inputted values
                model = (CompanyRegisterViewModel)TempData["regMod"];
            }
            return(View(model ?? new CompanyRegisterViewModel()));
        }
Esempio n. 4
0
        public async Task <ActionResult> CompanyRegister(CompanyRegisterViewModel model)
        {
            TheGarageDbContext            context         = new TheGarageDbContext();
            TheGarageData                 garageData      = new TheGarageData(context);
            UserRoleAdministrationService userRoleService = new UserRoleAdministrationService(garageData);
            ApplicationRole               role            = new ApplicationRole();

            role.Name = GlobalConstants.PendingClientRole;

            if (ModelState.IsValid)
            {
                var user = new User
                {
                    IsCompany       = true,
                    FirstName       = model.CompanyName,
                    UserName        = model.Email,
                    Email           = model.Email,
                    RequestDate     = model.RequestDate,
                    PlacesCount     = model.PlacesCount,
                    PhoneNumber     = model.PhoneNumber,
                    RequestedState  = model.States,
                    RequestedCity   = model.Cities,
                    RequestedGarage = model.Garages,
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    //System.Web.Security.Roles.AddUserToRole(model.Email, GlobalConstants.PendingClientRole);
                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(PartialView(model));
        }
Esempio n. 5
0
        public async Task <ActionResult> Company(CompanyRegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var image          = this.imageService.GetImage(Server.MapPath(DefaultImagePath));
                var convertedImage = this.imageService.ImageToByteArray(image);
                var user           = new Company {
                    CompanyName = model.CompanyName, Description = model.Description, UserImage = convertedImage, UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(new ApplicationDbContext()));
                if (!roleManager.RoleExists("Company"))
                {
                    var role = new IdentityRole();
                    role.Name = "Company";
                    roleManager.Create(role);
                }

                this.UserManager.AddToRole(user.Id, "Company");
                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

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

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Esempio n. 6
0
        public async Task <ActionResult> Register(CompanyRegisterViewModel model, bool?agreeTerms)
        {
            if (ModelState.IsValid)
            {
                if (agreeTerms == true)
                {
                    if (model.HeadCount != 0)
                    {
                        CreateDefaultRoles();
                        var user = new ApplicationUser {
                            UserName = model.Email, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName, IsAgreeTheTerms = true, Role = "SuperAdmin"
                        };
                        var result = await UserManager.CreateAsync(user, model.Password);

                        if (result.Succeeded)
                        {
                            var companyViewModel = new CompanyViewModel();
                            companyViewModel.Name        = model.Name;
                            companyViewModel.Sector      = model.Sector;
                            companyViewModel.HeadCount   = model.HeadCount;
                            companyViewModel.Description = model.Description;
                            var company = Mapper.Map <Company>(companyViewModel);
                            companyService.Insert(company);

                            var employeeViewModel = new EmployeeViewModel();
                            employeeViewModel.Email     = model.Email;
                            employeeViewModel.FirstName = model.FirstName;
                            employeeViewModel.LastName  = model.LastName;
                            employeeViewModel.Position  = model.Position;
                            employeeViewModel.UserName  = model.UserName;
                            var employee = Mapper.Map <Employee>(employeeViewModel);
                            employee.CompanyId = company.Id; //company index viewında yazdığım yorum satır için bu satırı yazdım.
                            employeeService.Insert(employee);

                            UserManager.AddToRole(user.Id, "SuperAdmin"); // CompanyRegister ile kayıt olan kullanıcıya SuperAdmin rolü atanır

                            await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                            // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                            // Send an email with this link
                            // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                            // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                            // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                            return(RedirectToAction("Index", "Home", new { area = "Admin" }));
                        }
                        AddErrors(result);
                    }
                    else
                    {
                        return(View(model));
                    }
                }
                else
                {
                    return(View(model));
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Esempio n. 7
0
        public ActionResult Register()
        {
            var companyRegisterModel = new CompanyRegisterViewModel();

            return(View(companyRegisterModel));
        }