Exemple #1
0
        public async Task <IActionResult> SignUp([FromForm] RegisterViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var result =
                await _apiTools.PostAsync <JwtTokenReturnModel>(CommonClientsDefaults.WebApiAccountsControllerRegister,
                                                                model);

            #region Token received (response from service)

            if (result.Token != null)
            {
                HttpContext.Response.Cookies.Append(MvcClientDefaults.InCookiesJwtTokenName, result.Token);
                await _signInManager.PasswordSignInAsync(model.Email, model.Password, true, false);

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

            AddErrors(result.Errors);
            model.Roles = Roles();

            return(View(model));

            #endregion
        }
Exemple #2
0
        private async Task PrepareAsync(CreateOrUpdateFilmViewModel model)
        {
            var selectedActors = await FetchSelectedActorsAsync(model);

            if (model.Film.FilmId == 0)
            {
                await _apiTools.PostAsync <FilmReturnModel>("https://localhost:5001/api/films/create",
                                                            new { model.Film.Title, model.Film.PublishYear, model.Film.Description, Actors = selectedActors });
            }
            else
            {
                await _apiTools.PostAsync <FilmReturnModel>("https://localhost:5001/api/films/update",
                                                            new
                {
                    model.Film.FilmId,
                    model.Film.Title,
                    model.Film.PublishYear,
                    model.Film.Description,
                    Actors = selectedActors
                });
            }
        }
Exemple #3
0
        private async Task PrepareAsync(CreateOrUpdateActorViewModel model)
        {
            var selectedFilms = await FetchSelectedFilmsAsync(model);

            if (model.Actor.ActorId == 0)
            {
                await _apiTools.PostAsync <ActorReturnModel>("https://localhost:5001/api/actors/create",
                                                             new { model.Actor.FirstName, model.Actor.LastName, model.Actor.Birthday, Films = selectedFilms });
            }
            else
            {
                await _apiTools.PostAsync <ActorReturnModel>("https://localhost:5001/api/actors/update",
                                                             new
                {
                    model.Actor.ActorId,
                    model.Actor.FirstName,
                    model.Actor.LastName,
                    model.Actor.Birthday,
                    Films = selectedFilms
                });
            }
        }