Exemple #1
0
        public PTWQuestion Update(int id, PTWQuestion question)
        {
            var que = (from x in _context.PTWSelectionQA
                       where x.ID == id
                       select x).FirstOrDefault();

            if (string.IsNullOrEmpty(question.Questions))
            {
                throw new ArgumentException("Question name should not be empty");
            }
            if (que.ID == id)
            {
                que.Questions = question.Questions;
                if (question.CreatedOn == null)
                {
                    que.CreatedOn = DateTime.Now;
                }
                if (question.ModifiedOn == null)
                {
                    que.ModifiedOn = DateTime.Now;
                }
            }

            if (_context.PTWSelectionQA.Any(x => x.Questions == question.Questions))
            {
                throw new AppException("Question name is already Exists");
            }
            _context.PTWSelectionQA.Update(que);
            _context.SaveChanges();

            return(que);
        }
Exemple #2
0
        public PTWQuestion Create(PTWQuestion question)
        {
            if (string.IsNullOrEmpty(question.Questions))
            {
                throw new ArgumentException("Question Name should not be empty ");
            }
            if (_context.PTWSelectionQA.Any(x => x.Questions == question.Questions))
            {
                throw new AppException("Question name is already Exists");
            }
            if (question.CreatedOn == null)
            {
                question.CreatedOn = DateTime.Now;
            }
            if (question.ModifiedOn == null)
            {
                question.ModifiedOn = DateTime.Now;
            }
            _context.PTWSelectionQA.Add(question);
            _context.SaveChanges();

            return(question);
        }