コード例 #1
0
        // POST api/<controller>
        public HttpResponseMessage Post(Api_Models.MstLibraryBook_ApiModel objBook)
        {
            try
            {
                Data.MstLibraryBook newBook = new Data.MstLibraryBook
                {
                    BookNumber         = objBook.BookNumber,
                    Title              = objBook.Title,
                    Author             = objBook.Author,
                    EditionNumber      = objBook.EditionNumber,
                    PlaceOfPublication = objBook.PlaceOfPublication,
                    CopyRightDate      = objBook.CopyRightDate,
                    ISBN            = objBook.ISBN,
                    CreatedByUserId = objBook.CreatedByUserId,
                    CreatedBy       = objBook.CreatedBy,
                    CreatedDate     = objBook.CreatedDate,
                    UpdatedByUserId = objBook.UpdatedByUserId,
                    UpdatedBy       = objBook.UpdatedBy,
                    UpdatedDate     = objBook.UpdatedDate,
                };
                db.MstLibraryBooks.InsertOnSubmit(newBook);
                db.SubmitChanges();

                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            catch (Exception e)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, e.Message));
            }
        }
コード例 #2
0
        // PUT api/<controller>/5
        public HttpResponseMessage Put(int id, Api_Models.MstLibraryBook_ApiModel objBook)
        {
            try
            {
                var book = from d in db.MstLibraryBooks
                           where d.Id == id
                           select d;

                if (book.Any())
                {
                    var updateBook = book.FirstOrDefault();
                    updateBook.BookNumber      = objBook.BookNumber;
                    updateBook.Title           = objBook.Title;
                    updateBook.Author          = objBook.Author;
                    updateBook.EditionNumber   = objBook.EditionNumber;
                    updateBook.CopyRightDate   = objBook.CopyRightDate;
                    updateBook.ISBN            = objBook.ISBN;
                    updateBook.CreatedByUserId = objBook.CreatedByUserId;
                    updateBook.CreatedBy       = objBook.CreatedBy;
                    updateBook.CreatedDate     = objBook.CreatedDate;
                    updateBook.UpdatedByUserId = objBook.UpdatedByUserId;
                    updateBook.UpdatedBy       = objBook.UpdatedBy;
                    updateBook.UpdatedDate     = objBook.UpdatedDate;
                    db.SubmitChanges();

                    return(Request.CreateResponse(HttpStatusCode.OK));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "Book not found!"));
                }
            }
            catch (Exception e)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, e.Message));
            }
        }