Пример #1
0
        public ActionResult RegisterServiceProvider(ServiceProviderRegisterViewModel model)
        {
            if (repo.GetAll().Where(x => x.Username == model.Username).FirstOrDefault() != null)
            {
                ModelState.AddModelError("", "Username already exists!");
            }
            else if (ModelState.IsValid)
            {
                ServiceProvider serpro = new ServiceProvider()
                {
                    NID        = model.NID,
                    Coverage   = model.Coverage,
                    JoinDate   = System.DateTime.Now,
                    Skills     = model.Skills,
                    Revenue    = 0,
                    Commission = 0,
                    Activated  = false
                };
                repoSerPro.Insert(serpro);
                repoSerPro.Submit();

                Account account = new Account()
                {
                    Name              = model.Name,
                    Password          = model.Password,
                    Username          = model.Username,
                    Email             = model.Email,
                    Mobile            = model.Mobile,
                    Gender            = model.Gender,
                    DateOfBirth       = model.DateOfBirth,
                    Address           = model.Address,
                    ServiceProviderId = serpro.Id,
                    ServiceProvider   = serpro,
                    ProfilePicture    = "",
                    UserType          = 3
                };
                repo.Insert(account);
                repo.Submit();
                return(Redirect("/"));
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }