示例#1
0
        public ActionResult Create(User user, int CustomerId)
        {
            if (isAuthorized(CustomerId) == AuthStates.UserAuth || isAuthorized(CustomerId) == AuthStates.NoAuth)
            {
                return(View("NotAuthorized"));
            }
            if (ModelState.IsValid)
            {
                user.IsContactForCustomer = new Customer()
                {
                    Id = CustomerId
                };

                var modelregister = new RegisterViewModel()
                {
                    Password        = user.Password,
                    ConfirmPassword = user.Password,
                    Email           = user.Email
                };
                var model = new CreateUserWithCustomModel()
                {
                    CustomerId = CustomerId,
                    User       = new User()
                };
                try
                {
                    var s = WebapiService.instance.PostAsync("/api/Account/Register", modelregister).Result;
                    var u = db.Create(user);
                    return(RedirectToAction("Details", "Customers", new { id = CustomerId }));
                }
                catch (ApiException ex)
                {
                    HandleBadRequest(ex);
                    if (!ModelState.IsValid)
                    {
                        return(View(model));
                    }
                    throw;
                }
            }
            var Model = new CreateUserWithCustomModel()
            {
                CustomerId = CustomerId,
                User       = new User()
            };

            return(View(Model));
        }
示例#2
0
        // GET: Users/Create
        public ActionResult Create(int?CustomerId)
        {
            if (CustomerId == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            if (isAuthorized(CustomerId.Value) == AuthStates.UserAuth || isAuthorized(CustomerId.Value) == AuthStates.NoAuth)
            {
                return(View("NotAuthorized"));
            }

            var Model = new CreateUserWithCustomModel()
            {
                Users      = db.ReadAll().Select(e => e.Email).ToList(),
                CustomerId = CustomerId.Value,
                User       = new User()
            };

            return(View(Model));
        }