コード例 #1
0
        public HttpResponseMessage AddSermon([FromBody] SermonModel s)
        {
            IEnumerable <SermonModel> sermon = _sermonServices.GetSermons();
            var checksermon = sermon.FirstOrDefault(se => se.SermonTitle == s.SermonTitle);

            if (checksermon != null)
            {
                return(this.Request.CreateResponse(HttpStatusCode.Conflict, "Sermon with the title exist "));
            }
            var model = s.Create(s);

            _context.Sermons.Add(model);
            _context.SaveChanges();
            return(this.Request.CreateResponse(HttpStatusCode.Created, "Successful"));
        }
コード例 #2
0
        public bool CreatSermon(SermonModel model)
        {
            try
            {
                //var isExist = _context.Sermons.Where(x => x. == model.DeptName).FirstOrDefault();
                //if (isExist != null) throw new Exception("Department already exist");

                //since a message can be preach twice
                var entity = model.Create(model);
                _context.SaveChanges();
            }
            catch (Exception xe)
            {
                throw xe;
            }

            return(true);
        }