Exemplo n.º 1
0
        public bool CreateRequest(Request request)
        {
            var newRequest = new Requests
            {
                SenderFirstName = request.senderFirstName,
                SenderLastName = request.senderLastName,
                SenderEmail = request.senderEmail,
                Subject = request.subject,
                Question = request.question,
                Date = request.date,
                Answered = request.answered
            };

            try
            {
                // save request
                db.Requests.Add(newRequest);
                db.SaveChanges();
            }
            catch (Exception e)
            {
                writeToLog(e);
                return false;
            }

            return true;
        }
Exemplo n.º 2
0
        public bool UpdateRequest(int id, Request request)
        {
            Requests foundRequest = db.Requests.FirstOrDefault(r => r.ID == id);

            if (foundRequest == null)
                return false;

            foundRequest.SenderFirstName = request.senderFirstName;
            foundRequest.SenderLastName = request.senderLastName;
            foundRequest.SenderEmail = request.senderEmail;
            foundRequest.Subject = request.subject;
            foundRequest.Question = request.question;
            foundRequest.Date = request.date;
            foundRequest.Answered = request.answered;

            try
            {
                db.SaveChanges();
            }
            catch (Exception e)
            {
                writeToLog(e);
                return false;
            }

            return true;
        }
Exemplo n.º 3
0
        public Request GetRequest(int id)
        {
            try
            {
                Requests oneDbRequest = db.Requests.Find(id);

                if (oneDbRequest == null)
                    return null;

                var oneRequest = new Request()
                {
                    id = oneDbRequest.ID,
                    senderFirstName = oneDbRequest.SenderFirstName,
                    senderLastName = oneDbRequest.SenderLastName,
                    senderEmail = oneDbRequest.SenderEmail,
                    subject = oneDbRequest.Subject,
                    question = oneDbRequest.Question,
                    date = oneDbRequest.Date,
                    answered = oneDbRequest.Answered
                };

                return oneRequest;
            }
            catch (Exception e)
            {
                writeToLog(e);
                return null;
            }
        }