Exemplo n.º 1
0
        public async Task <Dictionary <string, object> > CreateComment(Comment _input)
        {
            Dictionary <string, object> jsonObj = new Dictionary <string, object>();

            try
            {
                using (var _DbEntity = new adelankanotesContext())
                {
                    if (_input != null)
                    {
                        _input.CreatedDate  = DateTime.Now;
                        _input.ModifiedDate = DateTime.Now;

                        _DbEntity.Comments.Add(_input);
                        _DbEntity.SaveChanges();

                        jsonObj.Add("Code", 0);
                        jsonObj.Add("Status", "Success");
                        jsonObj.Add("Message", "Note Saved!");
                        jsonObj.Add("Data", null);
                    }
                    else
                    {
                        jsonObj.Add("Code", 1);
                        jsonObj.Add("Status", "Fail");
                        jsonObj.Add("Message", $"Something went wrong!");
                        jsonObj.Add("Data", null);
                    }
                }
            }
            catch (Exception ex)
            {
                jsonObj.Add("Code", 1);
                jsonObj.Add("Status", "Fail");
                jsonObj.Add("Message", $"{ex.InnerException?.Message}");
                jsonObj.Add("Data", null);
            }
            return(await Task.FromResult(jsonObj));
        }