public async Task <GenreDTO> AddGenre(GenreDTO Genre) { Genre newGenre = _mapper.Map <Genre>(Genre); await _genreRepository.AddGenre(newGenre); return(Genre); }
public async Task AddNewGenre(string name) { if (await CheckGenre(name) == false) { try { Genre g1 = new Genre(name); await _genreRep.AddGenre(g1); } catch (Exception e) { if (e is GenreException || e is DALException) { await GeneralLibraryLogic.SaveToLogFile(e.ToString()); throw new BLLGenreException("Cannot add a new genre atm try again later or call a manager"); } else { await GeneralLibraryLogic.SaveToLogFile(e.ToString()); throw new LibraryException("Unknown error inform a manager!"); } } } else { await GeneralLibraryLogic.SaveToLogFile("Genre Already Exist"); throw new LibraryException("Genre already exist"); } }
public async Task <IActionResult> CreateGenreAsync( [FromBody, SwaggerParameter(Description = "Genre to create", Required = true)] GenreToCreateDto genreToCreate, [FromHeader(Name = "Accept"), SwaggerParameter(Description = "media type to request between json or json+hateoas")] string mediaType) { var genreToAdd = Mapper.Map <Genre>(genreToCreate); _genreRepository.AddGenre(genreToAdd); if (!await _genreRepository.SaveChangesAsync()) { _logger.LogError("Saving changes to database while creating a genre failed"); } // mapped created genre back to genreDto to remove unnecessary information var genreToReturn = Mapper.Map <GenreDto>(genreToAdd); if (mediaType == "application/vnd.biob.json+hateoas") { var links = CreateLinksForGenre(genreToReturn.Id); var linkedGenre = genreToReturn.ShapeData(null) as IDictionary <string, object>; linkedGenre.Add("links", links); return(CreatedAtRoute("GetGenre", new { genreId = genreToReturn.Id }, linkedGenre)); } return(CreatedAtRoute("GetGenre", new { genreId = genreToReturn.Id }, genreToReturn)); }
public async Task <ActionResult> Add(GenreDetailViewModel vm) { await _genreRepository.AddGenre(new Genre { Name = vm.Name }); return(RedirectToAction("Index")); }
public ViewResult NewGenre() { Genre newGen = new Genre { Name = Request.Form["Name"] }; repository.AddGenre(newGen); repository.SaveContext(); return(View()); }
public async Task <ActionResult <GenreGetResponse> > CreateGenre(GenrePostRequest genre) { var genreEntity = _mapper.Map <Genre>(genre); genreEntity.Id = Guid.NewGuid(); _genreRepository.AddGenre(genreEntity); await _genreRepository.SaveAsync(); var genreGetResponse = _mapper.Map <GenreGetResponse>(genreEntity); //// return Created(GetResourceUrl(genreGetResponse.Id.ToString()), genreGetResponse); //// OR return(CreatedAtRoute( "GetGenre", new { version = HttpContext.GetRequestedApiVersion().ToString(), genreId = genreGetResponse.Id }, genreGetResponse)); }
public IActionResult AddMovie(Movie movieIn, string DirectorFName, string DirectorLName, string Genre, string AgeRating) { Genre matchedGenre = _genreList.GetGenreByName(Genre); if (matchedGenre != null) { movieIn.Genre = matchedGenre; } else { movieIn.Genre = _genreList.AddGenre(Genre); } Age_Rating matchedAge_Rating = _age_RatingList.GetAge_RatingByName(AgeRating); if (matchedAge_Rating != null) { movieIn.AgeRating = matchedAge_Rating; } else { ViewBag.Result = "There was an error Selecting age rating please Try Again."; } Director matchedDirector = _directorList.GetDirectorByName(DirectorFName, DirectorLName); if (matchedDirector != null) { movieIn.Director = matchedDirector; } else { movieIn.Director = _directorList.AddDirector(DirectorFName, DirectorLName); } _movieList.Add(movieIn); return(RedirectToAction("AdminHomepage")); }
public async Task AddNewBook(string name, string writer, string printdate, string publisher, string genre, string discount, string quantity, string price, string isbn, string edition, string summary) { Book b1 = new Book(); if (name == "" || writer == "" || printdate == "" || printdate == "" || publisher == "" || genre == "" || discount == "" || quantity == "" || price == "" || isbn == "" || edition == "" || summary == "") { await GeneralLibraryLogic.SaveToLogFile("All book fields must be full in order to add a new book!"); throw new BLLBookException("All book fields must be full in order to add a new book!"); } b1.Name = name; b1.Writer = writer; DateTime date; if (DateTime.TryParse(printdate, out date) == false) { await GeneralLibraryLogic.SaveToLogFile("Cannot Convert date to DateTime!"); throw new BLLBookException("Date Time Not in a correct format"); } b1.PrintDate = DateTime.Parse(printdate); b1.Publisher = publisher; try { Genre g1 = await _genreRep.GetGenre(genre); if (g1.Name == null) { g1.Name = genre; await _genreRep.AddGenre(g1); g1 = await _genreRep.GetGenre(genre); } b1.Genre = g1; } catch (Exception e) { if (e is GenreException || e is DALException) { await GeneralLibraryLogic.SaveToLogFile(e.ToString()); throw new BLLBookException("Cannot add a new book atm try again later"); } else { await GeneralLibraryLogic.SaveToLogFile(e.ToString()); throw new LibraryException("Unknown error inform a manager!"); } } int discountToAdd = 0; if (int.TryParse(discount, out discountToAdd) == false) { await GeneralLibraryLogic.SaveToLogFile("discount is not a number!"); throw new BLLBookException("discount is not a number!"); } if (discountToAdd < 0 || discountToAdd > 99) { await GeneralLibraryLogic.SaveToLogFile("Discount must be between 0-99"); throw new BLLBookException("Discount must be between 0-99"); } b1.Discount = discountToAdd; int quantityToAdd = 0; if (int.TryParse(quantity, out quantityToAdd) == false) { await GeneralLibraryLogic.SaveToLogFile("quantity is not a number"); throw new BLLBookException("quantity is not a number"); } if (quantityToAdd < 0) { await GeneralLibraryLogic.SaveToLogFile("Quantity cannot be negative!"); throw new BLLBookException("Quantity cannot be negative!"); } b1.Quantity = quantityToAdd; int priceToAdd = 0; if (int.TryParse(price, out priceToAdd) == false) { await GeneralLibraryLogic.SaveToLogFile("Price is not a number"); throw new BLLBookException("Price is not a number"); } if (priceToAdd < 0) { await GeneralLibraryLogic.SaveToLogFile("Price cannot be negative!"); throw new BLLBookException("Price cannot be negative!"); } b1.Price = priceToAdd; try { List <string> isbns = await _bookRep.GetAllIsbn(); if (isbns.Contains(isbn)) { await GeneralLibraryLogic.SaveToLogFile("ISBN Already Exist!"); throw new BLLBookException("ISBN Already Exist!"); } } catch (Exception e) { if (e is BookException || e is DALException) { await GeneralLibraryLogic.SaveToLogFile(e.ToString()); throw new BLLBookException("Cannot add a new book atm try again later"); } else { await GeneralLibraryLogic.SaveToLogFile(e.ToString()); throw new LibraryException("Unknown error inform a manager!"); } } b1.ISBN = isbn; b1.Edition = edition; b1.Summary = summary; try { await _bookRep.AddBook(b1); } catch (Exception e) { if (e is BookException || e is DALException) { await GeneralLibraryLogic.SaveToLogFile(e.ToString()); throw new BLLBookException("Cannot add a new book atm try again later or call a manager"); } else { await GeneralLibraryLogic.SaveToLogFile(e.ToString()); throw new LibraryException("Unknown error inform a manager!"); } } }
public IActionResult Add(Genre entity) { Repository.AddGenre(entity); return(RedirectToAction("List")); }
public void AddGenre(Genre genre) { genreRepo.AddGenre(genre); }
public async Task AddNewJournal(string name, string writer, string printdate, string publisher, string genre, string discount, string quantity, string price, string subject) { if (name == "" || writer == "" || printdate == "" || publisher == "" || genre == "" || discount == "" || quantity == "" || price == "" || subject == "") { await GeneralLibraryLogic.SaveToLogFile("All journal fields must be full"); throw new BLLJournalException("All journal fields must be full"); } Journal j1 = new Journal(); j1.Name = name; j1.Writer = writer; DateTime date; if (DateTime.TryParse(printdate, out date) == false) { await GeneralLibraryLogic.SaveToLogFile("Cannot convert printdate To DateTime!"); throw new BLLJournalException("Cannot convert printdate To DateTime!"); } j1.PrintDate = date; j1.Publisher = publisher; try { Genre g1 = await _genreRep.GetGenre(genre); if (g1.Name == null) { g1.Name = genre; await _genreRep.AddGenre(g1); g1 = await _genreRep.GetGenre(genre); } j1.Genre = g1; } catch (Exception e) { if (e is GenreException || e is DALException) { await GeneralLibraryLogic.SaveToLogFile(e.ToString()); throw new BLLJournalException("Cannot add a new journal atm try again later or call a manager"); } else { await GeneralLibraryLogic.SaveToLogFile(e.ToString()); throw new LibraryException("Unknown error inform a manager!"); } } int discountToAdd = 0; if (int.TryParse(discount, out discountToAdd) == false) { await GeneralLibraryLogic.SaveToLogFile("Discount must be a number!"); throw new BLLJournalException("Discount must be a number!"); } if (discountToAdd < 0 || discountToAdd > 99) { await GeneralLibraryLogic.SaveToLogFile("Discount must be between 0-99"); throw new BLLJournalException("Discount must be between 0-99"); } j1.Discount = discountToAdd; int quantityToAdd = 0; if (int.TryParse(quantity, out quantityToAdd) == false) { await GeneralLibraryLogic.SaveToLogFile("Quantity must be a number!"); throw new BLLJournalException("Quantity must be a number!"); } if (quantityToAdd < 0) { await GeneralLibraryLogic.SaveToLogFile("Quantity cannot be negative!"); throw new BLLJournalException("Quantity cannot be negative!"); } j1.Quantity = quantityToAdd; int priceToAdd = 0; if (int.TryParse(price, out priceToAdd) == false) { await GeneralLibraryLogic.SaveToLogFile("Price must be a number!"); throw new LibraryException("Price must be a number!"); } if (priceToAdd < 0) { await GeneralLibraryLogic.SaveToLogFile("Price cannot be negative!"); throw new LibraryException("Price cannot be negative!"); } j1.Price = priceToAdd; j1.Subject = subject; try { await _journalRep.AddJournal(j1); } catch (Exception e) { if (e is JournalException || e is DALException) { await GeneralLibraryLogic.SaveToLogFile(e.ToString()); throw new BLLJournalException("Cannot add a new journal atm try again later or call a manager"); } else { await GeneralLibraryLogic.SaveToLogFile(e.ToString()); throw new LibraryException("Unknown error inform a manager!"); } } }
public void Add(Genre genre) { _genreRepository.AddGenre(genre); }