public async Task <ActionResult> Post([FromBody] GenreCreateDTO model)
        {
            try
            {
                var entity = _automapper.Map <Genre>(model);
                await _db.AddAsync(entity);

                await _db.SaveChangesAsync();

                var genreDTO = _automapper.Map <GenreDTO>(entity);

                return(new CreatedAtRouteResult("GetGenreById", new { id = genreDTO.Id }, genreDTO));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }
        }
Example #2
0
        public async Task <IActionResult> Add(FilmViewModel model)
        {
            if (ModelState.IsValid)
            {
                string uniqueFileName = UploadedFile(model.Image);
                Film   film           = new Film
                {
                    Title     = model.Title,
                    Desc      = model.Desc,
                    Year      = model.Year,
                    Director  = model.Director,
                    UserEmail = User.Identity.Name,
                    Image     = uniqueFileName,
                };
                dbContext.Add(film);
                await dbContext.SaveChangesAsync();

                return(Redirect("~/Home/Index"));
            }
            return(View());
        }
Example #3
0
        public async Task <IActionResult> Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                User user = await dbContext.Users.FirstOrDefaultAsync(u => u.Email == model.Email);

                if (user == null)
                {
                    dbContext.Users.Add(new User {
                        Id = Guid.NewGuid(), Email = model.Email, Name = model.Name, Password = model.Password
                    });
                    await dbContext.SaveChangesAsync();
                    await Authenticate(model.Email);

                    return(Redirect("~/Home/Index"));
                }
                else
                {
                    ModelState.AddModelError("", "Пользователь уже существует");
                }
            }
            return(View(model));
        }