コード例 #1
0
 public bool Create(UserModel user)
 {
     try
     {
         _context.Users.Add(user);
         _context.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
コード例 #2
0
 public bool Create(CategoryModel category)
 {
     try
     {
         _context.Categories.Add(category);
         _context.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
コード例 #3
0
 public bool Create(BooksModel book)
 {
     try
     {
         _context.Books.Add(book);
         _context.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
コード例 #4
0
 public bool Create(RequestDetailsModel bbrd)
 {
     try
     {
         _context.RequestDetails.Add(bbrd);
         _context.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
コード例 #5
0
        public bool CreateRequest(int userId, List <int> bookIds)
        {
            try
            {
                var checkMonth = _context.Requests.Count(x => x.RequestUserId == userId &&
                                                         x.RequestDate.Month == DateTime.Now.Month &&
                                                         x.RequestDate.Year == DateTime.Now.Year);

                if (bookIds.Count() > 5 || checkMonth > 2)
                {
                    return(false);
                }
                else
                {
                    var request = new RequestModel
                    {
                        RequestUserId = userId,
                        RequestDate   = DateTime.Now,
                        RequestStatus = Status.Waiting
                    };
                    _context.Requests.Add(request);
                    _context.SaveChanges();

                    foreach (var item in bookIds)
                    {
                        var requestdetail = new RequestDetailsModel
                        {
                            RequestID = request.RequestID,
                            BookID    = item
                        };
                        _context.RequestDetails.Add(requestdetail);
                    }
                    _context.SaveChanges();
                    return(true);
                }
            }
            catch
            {
                return(false);
            }
        }
コード例 #6
0
        // PUT: odata/TitleLists(5)
        public IHttpActionResult Put([FromODataUri] int key, Delta <TitleList> patch)
        {
            Validate(patch.GetEntity());

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            TitleList titleList = db.TitleLists.Find(key);

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

            patch.Put(titleList);

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

            return(Updated(titleList));
        }
コード例 #7
0
        // PUT: odata/Fairies(5)
        public IHttpActionResult Put([FromODataUri] int key, Delta <Fairy> patch)
        {
            Validate(patch.GetEntity());

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Fairy fairy = db.Fairies.Find(key);

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

            patch.Put(fairy);

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

            return(Updated(fairy));
        }
コード例 #8
0
        // PUT: odata/BookConditions(5)
        public IHttpActionResult Put([FromODataUri] int key, Delta <BookCondition> patch)
        {
            Validate(patch.GetEntity());

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            BookCondition bookCondition = db.BookConditions.Find(key);

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

            patch.Put(bookCondition);

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

            return(Updated(bookCondition));
        }
コード例 #9
0
        // PUT: odata/CheckInRecords(5)
        public IHttpActionResult Put([FromODataUri] int key, Delta <CheckInRecord> patch)
        {
            Validate(patch.GetEntity());

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            CheckInRecord checkInRecord = db.CheckInRecords.Find(key);

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

            patch.Put(checkInRecord);

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

            return(Updated(checkInRecord));
        }
コード例 #10
0
 public void Add(Book entity)
 {
     _dbContext.Books.Add(entity);
     _dbContext.SaveChanges();
 }
コード例 #11
0
 protected void Save()
 {
     _context.SaveChanges();
 }