Exemple #1
0
        public async Task <IActionResult> PutBook(long id, Book book)
        {
            if (id != book.Id)
            {
                return(BadRequest());
            }

            _context.Entry(book).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BookExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> Create([Bind("Id,ExistingImage,ImageFile,Name,Description,IsActive")] PublisherCreateViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                Publisher publisher = _mapper.Map <Publisher>(viewModel);

                var result = _fileUpload.SaveFile(viewModel.ImageFile, uploadImagePath);
                publisher.Image = result.UniqueFileName;

                _context.Add(publisher);
                await _context.SaveChangesAsync();

                //return RedirectToAction(nameof(Index));
            }
            return(PartialView("_CreatePartial", viewModel));
        }
        public async Task <IActionResult> Create([Bind("Id,AudioFile,Description,Duration")] AudioFileCreateViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                AudioFile audioFile = _mapper.Map <AudioFile>(viewModel);
                var       result    = _fileUpload.SaveFile(viewModel.AudioFile, uploadAudioPath);
                audioFile.Name     = result.FileName;
                audioFile.FileSize = result.FileSize;
                audioFile.FilePath = result.UniqueFileName;

                _context.Add(audioFile);
                await _context.SaveChangesAsync();

                //return RedirectToAction(nameof(Index));
            }
            return(PartialView("_CreatePartial", viewModel));
        }
        public async Task <IActionResult> Create([Bind("Id,ImageFile,Name,Description,IsActive")] LanguageCreateViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                Language language = _mapper.Map <Language>(viewModel);

                var result = _fileUpload.SaveFile(viewModel.ImageFile, uploadImagePath);
                language.Image = result.UniqueFileName;

                _context.Add(language);
                await _context.SaveChangesAsync();

                CreateNotification("Contact saved!");
            }

            return(PartialView("_CreatePartial", viewModel));
        }
        public async Task <IActionResult> Create([Bind("Id,ExistingImage,ImageFile,FirstName,LastName,MiddleName,GenderId,EmailAddress,Email,PhoneNumber")] AuthorCreateViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                Author author = _mapper.Map <Author>(viewModel);

                var result = _fileUpload.SaveFile(viewModel.ImageFile, uploadImagePath);
                author.Image = result.UniqueFileName;

                _context.Add(author);
                await _context.SaveChangesAsync();

                //return RedirectToAction(nameof(Index));
            }

            ViewData["GenderId"] = new SelectList(_context.Genders, "Id", "Name");
            return(PartialView("_CreatePartial", viewModel));
        }
        public async Task <IActionResult> Create([Bind("Id,Name,Description")] GenderCreateViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var dateTime = DateTime.Now;

                Gender gender = new Gender
                {
                    Name        = viewModel.Name,
                    Description = viewModel.Description,
                    IsActive    = true,
                    CreatedAt   = dateTime,
                    ModifiedAt  = dateTime,
                };


                _context.Add(gender);
                await _context.SaveChangesAsync();

                //return RedirectToAction(nameof(Index));
            }
            return(PartialView("_CreatePartial", viewModel));
        }
        public async Task <IActionResult> Create([Bind("Id,ExistingCoverImage,CoverImageFile,Title,Summary,ReleaseDate,CategoryId,PublisherId,AuthorId,LanguageId,NarratorId,AudioId")] BookCreateViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                Book book = _mapper.Map <Book>(viewModel);

                var result = _fileUpload.SaveFile(viewModel.CoverImageFile, uploadImagePath);
                book.CoverImage = result.FileName;

                _context.Add(book);
                await _context.SaveChangesAsync();

                //return RedirectToAction(nameof(Index));
            }
            var authors = _context.Authors.Select(s =>
                                                  new
            {
                Id       = s.Id,
                FullName = string.Format("{0} {1}", s.FirstName, s.LastName)
            });

            var narrators = _context.Narrators.Select(s =>
                                                      new
            {
                Id       = s.Id,
                FullName = string.Format("{0} {1}", s.FirstName, s.LastName)
            });

            ViewData["AudioId"]     = new SelectList(_context.AudioFiles, "Id", "Name");
            ViewData["AuthorId"]    = new SelectList(authors, "Id", "FullName");
            ViewData["CategoryId"]  = new SelectList(_context.Categories, "Id", "Name");
            ViewData["LanguageId"]  = new SelectList(_context.Languages, "Id", "Name");
            ViewData["NarratorId"]  = new SelectList(narrators, "Id", "FullName");
            ViewData["PublisherId"] = new SelectList(_context.Publishers, "Id", "Name");

            return(PartialView("_CreatePartial", viewModel));
        }