private Guid CreatePublisher() { var publisher = new Publisher("Pearson"); var publisherRepository = new PublisherRepository(GetContext()); publisherRepository.Add(publisher); publisherRepository.SaveChanges(); return(publisher.Id); }
public ActionResult Create([Bind(Include = "Id,Name")] Publisher publisher) { if (ModelState.IsValid) { db.Add(publisher); return(RedirectToAction("Index")); } return(View(publisher)); }
public async Task <IActionResult> PostPublisher([FromBody] Publisher publisher) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } await _publisherRepository.Add(publisher); return(CreatedAtAction("GetPublisher", new { id = publisher.Id }, publisher)); }
public Publisher Create(PublisherCreateDto dto) { dto.Name = FormatString.Trim_MultiSpaces_Title(dto.Name, true); var isExist = GetDetail(dto.Name); if (isExist != null) { throw new Exception(dto.Name + " existed"); } var entity = new Publisher { Name = dto.Name, Image = FormatString.Trim_MultiSpaces_Title(dto.Image, true) }; return(repository.Add(entity)); }
public void Add(PostPublisherViewModel publisherView) { Publisher publisher = Mapper.Map <PostPublisherViewModel, Publisher>(publisherView); _publisherRepository.Add(publisher); }
public string get() { using (var ctx = new libraryContext()) { var AuthorRepo = new AuthorRepository(ctx); var PublisherRepo = new PublisherRepository(ctx); var BooksRepo = new BooksRepository(ctx); try { var authorFile = @"E:\OneDrive - The University of Texas at Dallas\Spring18\DB\Projects\project1\books.csv"; //var borrowerFile = ""; List <Model> list = new List <Model>(); var fileStream = new FileStream(authorFile, FileMode.Open, FileAccess.Read); HashSet <string> authors = new HashSet <string>(); HashSet <string> publishers = new HashSet <string>(); using (var streamReader = new StreamReader(fileStream, Encoding.UTF8)) { string line; line = streamReader.ReadLine(); while ((line = streamReader.ReadLine()) != null) { var temp = line.Split('\t'); foreach (var author in temp[3].Split(',')) { authors.Add(author); } publishers.Add(temp[5]); int pages = Int16.Parse(temp[6]); var model = new Model(temp[0], temp[2], temp[3].Split(','), temp[4], temp[5], pages); list.Add(model); //BooksRepo.Add(temp[0], temp[2], temp[5], Int16.Parse(temp[6]), temp[4], temp[3].Split(',')); //ctx.SaveChanges(); } } foreach (var author in authors) { AuthorRepo.Add(author); } foreach (var publisher in publishers) { PublisherRepo.Add(publisher); } ctx.SaveChanges(); var count = 0; foreach (var item in list) { count++; BooksRepo.Add(item.isbn, item.title, item.cover, item.pages, item.publisher, item.authors); if (count % 5000 == 0) { Console.Write(ctx.SaveChanges()); } } ctx.SaveChanges(); } catch (Exception e) { return(e.Message); } return("Success"); } }