public IActionResult Create([FromBody] TechTalk techTalk) { if (techTalk == null) { return(BadRequest()); } Console.WriteLine("Saving Tech talk to database."); Console.WriteLine($"Tech Talk Id : {techTalk.Id}"); Console.WriteLine($"Tech Talk Name : {techTalk.TechTalkName}"); Console.WriteLine($"Category : {techTalk.CategoryId}"); Console.WriteLine($"Level : {techTalk.LevelId}"); try { _context.TechTalk.Add(techTalk); _context.Entry(techTalk.Category).State = EntityState.Unchanged; _context.Entry(techTalk.Level).State = EntityState.Unchanged; _context.SaveChanges(); } catch (Exception ex) { Console.WriteLine("Inside exception block"); Console.WriteLine(ex.Message); Console.WriteLine(ex.InnerException); } return(Ok()); }
private void RabbitMQEventHandler(object model, BasicDeliverEventArgs ea) { Console.WriteLine("Inside RabbitMQ receiver..."); var body = ea.Body; var message = Encoding.UTF8.GetString(body); var techTalk = JsonConvert.DeserializeObject <TechTalk>(message); Console.WriteLine($"Received message {message}"); Console.WriteLine($"Tech Talk Id : {techTalk.Id}"); Console.WriteLine($"Tech Talk Name : {techTalk.TechTalkName}"); Console.WriteLine($"Category : {techTalk.CategoryId}"); Console.WriteLine($"Level : {techTalk.LevelId}"); try { Console.WriteLine(_context.Database.GetDbConnection().ConnectionString); _context.TechTalk.Add(techTalk); _context.Entry(techTalk.Category).State = EntityState.Unchanged; _context.Entry(techTalk.Level).State = EntityState.Unchanged; _context.SaveChanges(); } catch (Exception ex) { Console.WriteLine("Inside exception block"); Console.WriteLine(ex.Message); Console.WriteLine(ex.InnerException); } Console.WriteLine("TechTalk persisted successfully"); }
public IActionResult Update(int id, [FromBody] TechTalk item) { if (item == null || !item.Id.Equals(id)) { return(BadRequest()); } var techTalk = _context.TechTalk.FirstOrDefault(t => t.Id.Equals(id)); if (techTalk == null) { return(NotFound()); } techTalk.TechTalkName = item.TechTalkName; _context.TechTalk.Update(techTalk); _context.SaveChanges(); return(new NoContentResult()); }
public IActionResult Create([FromBody] TechTalkDTO techTalkDto) { if (techTalkDto == null) { return(BadRequest()); } TechTalk techTalk = new TechTalk { TechTalkName = techTalkDto.TechTalkName, CategoryId = techTalkDto.CategoryId, Category = _context.Categories.FirstOrDefault(x => x.Id == techTalkDto.CategoryId), LevelId = techTalkDto.LevelId, Level = _context.Levels.FirstOrDefault(x => x.Id == techTalkDto.LevelId) }; Console.WriteLine("Saving Tech talk to database."); Console.WriteLine($"Tech Talk Id : {techTalk.Id}"); Console.WriteLine($"Tech Talk Name : {techTalk.TechTalkName}"); Console.WriteLine($"Category : {techTalk.CategoryId}"); Console.WriteLine($"Level : {techTalk.LevelId}"); try { _context.TechTalk.Add(techTalk); _context.Entry(techTalk.Category).State = EntityState.Unchanged; _context.Entry(techTalk.Level).State = EntityState.Unchanged; _context.SaveChanges(); } catch (Exception ex) { Console.WriteLine("Inside exception block"); Console.WriteLine(ex.Message); Console.WriteLine(ex.InnerException); } return(Ok()); }