public ContentRatingModel GetByContentId(int id)
        {
            Connection();
            List <ContentRatingModel> contentList        = new List <ContentRatingModel>();
            ContentRatingModel        contentRatingModel = new ContentRatingModel();
            SqlCommand command = new SqlCommand("GetContentRatingByID", _connect);

            command.Parameters.AddWithValue("@ContentRatingID", id);
            command.CommandType = CommandType.StoredProcedure;
            SqlDataAdapter dataAdapter = new SqlDataAdapter(command);
            DataTable      dataTable   = new DataTable();

            _connect.Open();
            dataAdapter.Fill(dataTable);
            _connect.Close();

            //Bind AuthorModel generic list using LINQ
            contentList = (from DataRow dataRow in dataTable.Rows

                           select new ContentRatingModel()
            {
                ContentRatingId = Convert.ToInt32(dataRow["ContentRatingID"]),
                ContentRatingName = Convert.ToString(dataRow["ContentRating"]),
            }).ToList();

            contentRatingModel = contentList[0];

            return(contentRatingModel);
        }
Example #2
0
        public ActionResult AddContentRating(ContentRatingModel contentRating)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    ContentRatingRepository ContentRatingRepo = new ContentRatingRepository();
                    ContentRatingRepo.AddContentRating(contentRating);

                    var profileData = Session["UserProfile"] as UserSession;
                    var logModel    = new LogModel
                    {
                        UserId    = profileData.UserID,
                        TableName = "Content Rating",
                        Activity  = "Added Content Rating",
                        LogDate   = DateTime.Now
                    };
                    var logRepository = new logRepository();
                    logRepository.AddLog(logModel);
                }

                return(RedirectToAction("GetAllContentRatingDetails"));
            }
            catch
            {
                return(RedirectToAction("GetAllContentRatingDetails"));
            }
        }
        //To Add ContentRating details
        public bool AddContentRating(ContentRatingModel obj)
        {
            Connection();
            SqlCommand command = new SqlCommand("AddNewContentRating", _connect);

            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.AddWithValue("@ContentRating", obj.ContentRatingName);

            _connect.Open();
            var i = command.ExecuteNonQuery();

            _connect.Close();
            if (i >= 1)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #4
0
 public ActionResult EditContentRatingDetails(int id, ContentRatingModel contentRating)
 {
     try
     {
         ContentRatingRepository ContentRatingRepo = new ContentRatingRepository();
         ContentRatingRepo.UpdateContentRating(contentRating);
         var profileData = Session["UserProfile"] as UserSession;
         var logModel    = new LogModel
         {
             UserId    = profileData.UserID,
             TableName = "Content Rating",
             Activity  = "Updated Rating",
             LogDate   = DateTime.Now
         };
         var logRepository = new logRepository();
         logRepository.AddLog(logModel);
         return(RedirectToAction("GetAllContentRatingDetails"));
     }
     catch
     {
         return(RedirectToAction("GetAllContentRatingDetails"));
     }
 }
Example #5
0
        public ActionResult AddLoan(LoanModel loanModel)
        {
            try
            {
                LoanRepository          loanRepository          = new LoanRepository();
                copiesRepository        copiesRepository        = new copiesRepository();
                BookRepository          bookRepository          = new BookRepository();
                ContentRatingRepository contentRatingRepository = new ContentRatingRepository();
                MemberRepository        memberRepository        = new MemberRepository();
                MembershipRepository    membershipRepository    = new MembershipRepository();

                List <MemberModel> memberList   = new List <MemberModel>();
                LoanModel          newLoanModel = new LoanModel();
                newLoanModel.MemberList = memberRepository.GetAllMember();

                CopiesModel copiesModel = new CopiesModel();
                copiesModel = copiesRepository.SearchCopyById(loanModel.CopiesId);

                BookModel bookModel = new BookModel();
                bookModel = bookRepository.SearchBookById(copiesModel.BookId);

                if (bookModel.BookType.Equals("Reference Book"))
                {
                    ViewBag.Message = "Reference Books Can't be Loaned";
                    return(View(newLoanModel));
                }

                ContentRatingModel contentRatingModel = new ContentRatingModel();
                contentRatingModel = contentRatingRepository.GetByContentId(bookModel.ContentRatingId);

                MemberModel memberModel = new MemberModel();
                memberModel = memberRepository.SearchMemberById(loanModel.MembershipId);

                if (contentRatingModel.ContentRatingName.Equals("18+"))
                {
                    var today    = DateTime.Today;
                    var age      = Convert.ToDateTime(memberModel.Dob);
                    var todayAge = today.Year - age.Year;
                    if (todayAge < 18)
                    {
                        ViewBag.Message = "Age Restricted Books Are Not Allowed";
                        return(View(newLoanModel));
                    }
                }

                MembershipModel membershipModel = new MembershipModel();
                membershipModel = membershipRepository.GetMembershipByID(memberModel.MembershipId);

                BookCopies bookCopiesModel = new BookCopies();
                bookCopiesModel = loanRepository.GetAllLoanByMemberID(memberModel.MemberId);

                if (bookCopiesModel.Quantities >= membershipModel.NoOfBooks)
                {
                    ViewBag.Message = "No More Books Can be Loaned";
                    return(View(newLoanModel));
                }

                DateTime returnedDate = Convert.ToDateTime(loanModel.LoanDate);
                loanModel.ReturnDate = returnedDate.AddDays(14).ToString("yyyy MMMM dd");
                loanRepository.AddLoan(loanModel);
                copiesRepository.UpdateCopiesStatus(loanModel.CopiesId);

                var profileData = Session["UserProfile"] as UserSession;
                var logModel    = new LogModel
                {
                    UserId    = profileData.UserID,
                    TableName = "Loan",
                    Activity  = "Added Loan",
                    LogDate   = DateTime.Now
                };
                var logRepository = new logRepository();
                logRepository.AddLog(logModel);
                return(RedirectToAction("Dashboard", "Home"));
            }
            catch
            {
                return(RedirectToAction("Index", "Home"));
            }
        }