public IHttpActionResult UpdateBuyerAndSeller(int id, BuyerAndSellerDto buyandsellDto) { if (!ModelState.IsValid) { return(BadRequest()); } var renterInDb = _context.BuyerAndSellerz.SingleOrDefault(r => r.Id == id); if (renterInDb == null) { return(NotFound()); } Mapper.Map(buyandsellDto, renterInDb); _context.SaveChanges(); return(Ok(buyandsellDto)); }
public IHttpActionResult CreateBuyerAndSeller(BuyerAndSellerDto buyandsellDto) { buyandsellDto.CreatedDate = DateTime.Now; try { if (!ModelState.IsValid) { return(BadRequest()); } var buyerandseller = Mapper.Map <BuyerAndSellerDto, BuyerAndSeller>(buyandsellDto); _context.BuyerAndSellerz.Add(buyerandseller); _context.SaveChanges(); buyandsellDto.Id = buyerandseller.Id; return(Created(new Uri(Request.RequestUri + "/" + buyandsellDto.Id), new { buyandsellDto, msg = "Buyers And Sellers successfully Done !!!" })); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); Console.WriteLine(ex.Message); Console.WriteLine(ex.InnerException); throw; } }