Beispiel #1
0
        public async Task <IActionResult> Post([FromBody] dynamic bodyObject)
        {
            DataBaseModel newObj = new DataBaseModel
            {
                Id    = bodyObject.Id,
                Title = bodyObject.Title
            };

            await _context.DataBaseModels.AddAsync(newObj);

            _context.SaveChanges();
            return(Ok());
            //return Ok(_context.DataBaseModels.ToList());
        }
Beispiel #2
0
        public bool Save()
        {
            try
            {
                return(_context.SaveChanges() > 0);
            }
            catch (SqlException ex)
            {
                StringBuilder errorMessages = new StringBuilder();

                for (int i = 0; i < ex.Errors.Count; i++)
                {
                    errorMessages.Append("Index #" + i + "\n" +
                                         "Message: " + ex.Errors[i].Message + "\n" +
                                         "LineNumber: " + ex.Errors[i].LineNumber + "\n" +
                                         "Source: " + ex.Errors[i].Source + "\n" +
                                         "Procedure: " + ex.Errors[i].Procedure + "\n");
                }
                Console.WriteLine(errorMessages.ToString());
            }
            return(false);
        }
Beispiel #3
0
 public bool SaveChanges()
 {
     return(_context.SaveChanges() > 0);
 }