public ActionResult Update(Models.Publisher publisher) { Data.Publisher persistentPublisher = Mapper.Map<Models.Publisher, Data.Publisher>(publisher); Publishing.UpdatePublisher(persistentPublisher); return Content(JsonConvert.SerializeObject(Mapper.Map<Data.Publisher, Models.Publisher>(persistentPublisher))); }
public async Task <IActionResult> PutPublisher(int id, Models.Publisher publisher) { if (id == null) { return(StatusCode(StatusCodes.Status500InternalServerError, "Could not found the ID: " + id)); } if (id != publisher.PublisherId) { return(StatusCode(StatusCodes.Status500InternalServerError, "Could not found the ID: " + id)); } try { await _publisherService.PutPublisher(id, publisher); return(StatusCode(StatusCodes.Status200OK, "Publisher succesfully updated! ")); } catch (DbUpdateConcurrencyException) { Models.Publisher publisherModel = await _publisherService.GetPublisher(id); if (publisherModel == null) { return(NotFound()); } else { throw; } } }
public async Task <Models.Publisher> DeletePublisher(int id) { var result = await _publishersRepository.DeletePublisher(id); Models.Publisher publisherModel = _mapper.Map <Models.Publisher>(result); return(publisherModel); }
public async Task <Models.Publisher> PutPublisher(int id, Models.Publisher Publisher) { Data.Entities.Publisher publisherEnt = _mapper.Map <Data.Entities.Publisher>(Publisher); Data.Entities.Publisher publisherReturn = await _publishersRepository.PutPublisher(id, publisherEnt); return(_mapper.Map <Models.Publisher>(publisherReturn)); }
public async Task <Models.Publisher> GetPublisher(int?id) { var result = await _publishersRepository.GetPublisher(id); Models.Publisher publisher = _mapper.Map <Models.Publisher>(result); return(publisher); }
public async Task <Models.Publisher> PostPublisher(Models.Publisher Publisher) { Data.Entities.Publisher publisherEnt = _mapper.Map <Data.Entities.Publisher>(Publisher); var result = await _publishersRepository.PostPublisher(publisherEnt); Models.Publisher PublisherModel = _mapper.Map <Models.Publisher>(result); return(PublisherModel); }
public async Task <ActionResult <Models.Publisher> > PostPublisher(Models.Publisher publisher) { if (publisher == null) { return(StatusCode(StatusCodes.Status400BadRequest, "Bad request, verify the Publisher's Information ")); } return(await _publisherService.PostPublisher(publisher)); }
public async Task EnsureData() { var countryBrasil = new Models.Country { Name = "Brasil" }; if (!_dbContext.Countries.Any()) _dbContext.Countries.Add(countryBrasil); if (!_dbContext.Publishers.Any()) { var jbc = new Models.Publisher { Name = "JBC", Active = true, Country = countryBrasil }; _dbContext.Publishers.Add(jbc); } await _dbContext.SaveChangesAsync(); }
// GET: Demo public ActionResult Index(string inputValue) { ViewBag.myMessage = "Hi from controller!! This is from " + inputValue; List <Publisher> list = new List <Publisher>(); try { // runs stored procedure and returns data to main page using (SqlConnection con = new SqlConnection()) { String sql = @"select * from publishers"; con.ConnectionString = @"Server=comp1630.database.windows.net;Database=pubs;User Id=readonlylogin;Password=;"; DataTable dt = new DataTable(); SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = new SqlCommand(sql, con); da.Fill(dt); foreach (DataRow row in dt.Rows) { var pub = new Models.Publisher(); pub.Name = row["pub_name"].ToString(); pub.City = row["city"].ToString(); list.Add(pub); } } return(View(list)); } catch { return(View("Error")); } }
public async System.Threading.Tasks.Task <Microsoft.AspNetCore.Mvc.ActionResult <Models.Publisher> > PostPublisher(Models.Publisher publisher) { _context.Publishers.Add(publisher); await _context.SaveChangesAsync(); return(CreatedAtAction("GetPublisher", new { id = publisher.PubId }, publisher)); }
public async System.Threading.Tasks.Task <Microsoft.AspNetCore.Mvc.IActionResult> PutPublisher(int id, Models.Publisher publisher) { if (id != publisher.PubId) { return(BadRequest()); } _context.Entry(publisher).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PublisherExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }