コード例 #1
0
        public int Post(Models.News value)
        {
            try
            {
                Data.MstNew NewNews = new Data.MstNew();

                DateTime myDate = Convert.ToDateTime(value.NewsDate, new CultureInfo("en-US"));

                SqlDateTime NewsDate = new SqlDateTime(new DateTime(Convert.ToDateTime(myDate).Year, +
                                                                    Convert.ToDateTime(myDate).Month, +
                                                                    Convert.ToDateTime(myDate).Day));


                NewNews.NewsDate    = NewsDate.Value;
                NewNews.News        = value.NewsDescription;
                NewNews.Particulars = value.Particulars;

                db.MstNews.InsertOnSubmit(NewNews);
                db.SubmitChanges();

                return(NewNews.Id);
            }
            catch
            {
                return(0);
            }
        }
コード例 #2
0
        public HttpResponseMessage Delete(int Id)
        {
            Data.MstNew DeleteNews = db.MstNews.Where(d => d.Id == Id).First();

            if (DeleteNews != null)
            {
                db.MstNews.DeleteOnSubmit(DeleteNews);
                try
                {
                    db.SubmitChanges();
                    return(Request.CreateResponse(HttpStatusCode.OK));
                }
                catch
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest));
                }
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }
        }