Example #1
0
        public IHttpActionResult PostCOLLECTION(COLLECTION cOLLECTION)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.COLLECTION.Add(cOLLECTION);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (COLLECTIONExists(cOLLECTION.id_collection))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = cOLLECTION.id_collection }, cOLLECTION));
        }
Example #2
0
        /// <summary>
        /// 说明:<调用函数调用InsertCollection函数可以完成对收藏夹增加一条记录的功能>
        /// </summary>
        /// <param name="<newCollection>"><接受调用函数传入的一个COLLECTION对象></param>
        /// <returns><操作成功返回True,否则返回False> </returns>
        ///<exception>数据库增加操作异常</exception>

        public bool InsertCollection(COLLECTION newCollection)
        {
            //创建数据库实体类对象
            _entity = new WATCHMOVIEEntities();

            bool isSucceed = false;

            //添加记录到内存
            _entity.AddToCOLLECTION(newCollection);

            //保存修改到数据库
            try
            {
                int i = _entity.SaveChanges();
                isSucceed = true;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                //异常处理?
                return(false);
            }

            //撤销entity对象
            _entity.Dispose();

            return(isSucceed);
        }
Example #3
0
        public IHttpActionResult PutCOLLECTION(int id, COLLECTION cOLLECTION)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != cOLLECTION.id_collection)
            {
                return(BadRequest());
            }

            db.Entry(cOLLECTION).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!COLLECTIONExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Example #4
0
        public ActionResult DeleteConfirmed(string id)
        {
            COLLECTION collection = db.COLLECTIONs.Find(id);

            db.COLLECTIONs.Remove(collection);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #5
0
        //
        // GET: /COLLECTIONAdmin/Details/5

        public ActionResult Details(string id = null)
        {
            COLLECTION collection = db.COLLECTIONs.Find(id);

            if (collection == null)
            {
                return(HttpNotFound());
            }
            return(View(collection));
        }
Example #6
0
 public ActionResult Edit(COLLECTION collection)
 {
     if (ModelState.IsValid)
     {
         db.Entry(collection).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(collection));
 }
Example #7
0
        public IHttpActionResult GetCOLLECTION(int id)
        {
            COLLECTION cOLLECTION = db.COLLECTION.Find(id);

            if (cOLLECTION == null)
            {
                return(NotFound());
            }

            return(Ok(cOLLECTION));
        }
Example #8
0
        public ActionResult Create(COLLECTION collection)
        {
            if (ModelState.IsValid)
            {
                db.COLLECTIONs.Add(collection);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(collection));
        }
Example #9
0
        public IHttpActionResult DeleteCOLLECTION(int id)
        {
            COLLECTION cOLLECTION = db.COLLECTION.Find(id);

            if (cOLLECTION == null)
            {
                return(NotFound());
            }

            db.COLLECTION.Remove(cOLLECTION);
            db.SaveChanges();

            return(Ok(cOLLECTION));
        }
Example #10
0
        /// <summary>
        /// 说明:<重载InsertCollection >
        /// </summary>
        /// <param name="<newUserId>" name="<newMovieId>">
        /// <接受调用函数传入COLLECTION的三个字段作为参数></param>
        /// <returns><操作成功返回True,否则返回False> </returns>
        ///<exception>数据库增加操作异常</exception>

        //public bool InsertCollection(int newUserId, int newMovieId)
        //{
        //    //创建数据库实体类对象
        //    _entity = new WATCHMOVIEEntities();

        //    bool isSucceed = false;

        //    //创建一个临时COLLECTION对象
        //    COLLECTION collection = new COLLECTION();


        //    //collection.id = newId;
        //    collection.user_id = newUserId;
        //    collection.movie_id = newMovieId;

        //    //添加记录到内存
        //    _entity.AddToCOLLECTION(collection);

        //    //保存修改到数据库
        //    try
        //    {
        //        int i = _entity.SaveChanges();
        //        isSucceed = true;
        //    }
        //    catch (Exception ex)
        //    {
        //        //异常处理?
        //        return false;
        //    }

        //    //撤销数据库实体
        //    _entity.Dispose();

        //    return isSucceed;
        //}
        public bool InsertCollection(int newUserId, int newMovieId)
        {
            //创建数据库实体类对象
            _entity = new WATCHMOVIEEntities();

            bool isSucceed = false;

            var result = from c in _entity.COLLECTION
                         where c.user_id == newUserId && c.movie_id == newMovieId
                         select c;

            if (result.Count() > 0)
            {
                return(isSucceed);
            }
            //创建一个临时COLLECTION对象
            COLLECTION collection = new COLLECTION();


            //collection.id = newId;
            collection.user_id  = newUserId;
            collection.movie_id = newMovieId;


            //添加记录到内存
            _entity.AddToCOLLECTION(collection);

            //保存修改到数据库
            try
            {
                int i = _entity.SaveChanges();
                isSucceed = true;
            }
            catch (Exception ex)
            {
                //异常处理?
                Console.WriteLine(ex);
                return(false);
            }

            //撤销数据库实体
            _entity.Dispose();

            return(isSucceed);
        }