Пример #1
0
        public IEnumerable <MessageModel> GetMessages()
        {
            using (var db = new MessageBoardEntities())
            {
                var messages = db.Messages.ToList();

                messages.ForEach(message => MessageModels.Add(new MessageModel()
                {
                    Title         = message.Title,
                    Body          = message.Body,
                    DateOfMessage = message.DateOfMessage
                }));

                return(MessageModels);
            }
        }
Пример #2
0
        public void SaveMessage(MessageModel message)
        {
            try
            {
                using (var db = new MessageBoardEntities())
                {
                    db.Messages.Add(new Message()
                    {
                        Title         = message.Title,
                        Body          = message.Body,
                        DateOfMessage = message.DateOfMessage
                    });

                    db.SaveChanges();
                }
            }
            catch (Exception)
            {
                throw new FaultException("Your message couldn't be saved, please try again later.");
            }
        }