示例#1
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            if (Int32.TryParse(Request.QueryString["id"], out bookId))   //TryParse returns true/false.
            {
                using (Entities db = new Entities())
                {
                    ReservationManager manager = new ReservationManager(db);
                    manager.ReserveBook(bookId, User.Identity.GetUserId());
                    manager.SendNotification("*****@*****.**", bookId, User.Identity.GetUserId());

                }
                Response.Redirect("BookReserved.aspx");

            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            using (Entities db = new Entities())
            {
                ReservationManager resMan = new ReservationManager(db);

                List<ReservationInfo> reservations = resMan.GetReservations();

                if (reservations.Count == 0)
                {
                    Button1.Visible = false;
                }

                GridView1.DataSource = reservations;
                GridView1.DataBind();
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!User.Identity.IsAuthenticated)
            {
                Response.Redirect("~/Account/Login.aspx");
            }

            if (!IsPostBack)
            {
                // Render success message
                var message = Request.QueryString["m"];
                if (message != null)
                {
                    // Strip the query string from action
                    Form.Action = ResolveUrl("~/Account/ManageAccount.aspx");

                    SuccessMessage =
                        message == "ChangePwdSuccess" ? "Vaše heslo bylo změněno."

                        : String.Empty;
                    //successMessage.Visible = !String.IsNullOrEmpty(SuccessMessage);
                    successDiv.Visible = !String.IsNullOrEmpty(SuccessMessage);
                }
                EntityDataSource1.WhereParameters.Clear();
                EntityDataSource1.WhereParameters.Add("UserId", System.Data.DbType.String, User.Identity.GetUserId());
            }
            // Loads user reservation table
            using (Entities db = new Entities())
            {
                ReservationManager resMan = new ReservationManager(db);
                if (Int32.TryParse(Request.QueryString["resid"], out _resId))
                {
                    resMan.DeleteUserReservation(_resId, User.Identity.GetUserId());
                }
                List<UserResInfo> reservations = resMan.GetUserReservations(User.Identity.GetUserId());
                ResView.DataSource = reservations;
                ResView.DataBind();
                //Louads user lendings table
                LendingManager lenMan = new LendingManager(db);
                List<UserLendInfo> lendings = lenMan.GetUserLendings(User.Identity.GetUserId());
                LendView.DataSource = lendings;
                LendView.DataBind();
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            using (Entities db = new Entities())
            {
                ReservationManager resMan = new ReservationManager(db);
                //Retrieving list of reservations back from GridView DataSource
                List<ReservationInfo> reservations = (List<ReservationInfo>)GridView1.DataSource;

                //Selected index in GridView matches an index in retrieved ListView,so you can get specific info about reservation as following.
                int bookId = reservations[GridView1.SelectedIndex].BookId;
                string userId = reservations[GridView1.SelectedIndex].userId;
                resMan.LendBook(bookId, userId);

                reservations = resMan.GetReservations();

                if (reservations.Count == 0)
                {
                    Button1.Visible = false;
                }

                GridView1.DataSource = reservations;
                GridView1.DataBind();
            }
        }
示例#5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string soonFileName = Server.MapPath("~/Management/Messages/AboutExpireMessage.txt");
            string expFileName = Server.MapPath("~/Management/Messages/ExpireMessage.txt");
            string lateFileName = Server.MapPath("~/Management/Messages/LateExpireMessage.txt");
            string adminFileName = Server.MapPath("~/Management/Messages/AdminExpireMessage.txt");
            DateTime soonExpDate = DateTime.Now.Date.AddDays(3);
            DateTime expDate = DateTime.Now.Date;
            DateTime lateExpDate = DateTime.Now.Date.AddDays(-7);
            MailSender ms = new MailSender();
            MailMessage message = new MailMessage();
            message.Subject = "Scifiknihovna.cz - Upozornění";

            ExpireManager expMan = new ExpireManager();
            List<Lending> soonExpLendings = expMan.GetExpires(soonExpDate);
            List<Lending> expLendings = expMan.GetExpires(expDate);
            List<Lending> lateExpLendings = expMan.GetExpires(lateExpDate);
            List<Reservation> expReservations = expMan.GetResExpires(expDate);
            using (Entities db = new Entities())
            {

                // send notification emails before expiration
                if (soonExpLendings.Count != 0)
                {
                    foreach (Lending l in soonExpLendings)
                    {

                        string mailBody = File.ReadAllText(soonFileName);

                        var titul = (from b in db.Books
                                     where l.Book_ID.Equals(b.ID)
                                     select b.Titul).Single();
                        var autor = (from b in db.Books
                                     where l.Book_ID.Equals(b.ID)
                                     select b.Autor).Single();

                        mailBody = mailBody.Replace("##Title##", titul.ToString());
                        mailBody = mailBody.Replace("##Author##", autor.ToString());

                        message.Body = mailBody;

                        ms.SendMail(l.User_ID, message);
                    }
                }
                //send notification email at expiration
                if (expLendings.Count != 0)
                {
                    foreach (Lending l in expLendings)
                    {

                        string mailBody = File.ReadAllText(expFileName);

                        var titul = (from b in db.Books
                                     where l.Book_ID.Equals(b.ID)
                                     select b.Titul).Single();
                        var autor = (from b in db.Books
                                     where l.Book_ID.Equals(b.ID)
                                     select b.Autor).Single();

                        mailBody = mailBody.Replace("##Title##", titul.ToString());
                        mailBody = mailBody.Replace("##Author##", autor.ToString());

                        message.Body = mailBody;

                        ms.SendMail(l.User_ID,message);

                    }
                }

                //send notification email week after expiration

                if (lateExpLendings.Count != 0)
                {
                    foreach (Lending l in lateExpLendings)
                    {

                        string mailBody = File.ReadAllText(lateFileName);

                        var titul = (from b in db.Books
                                     where l.Book_ID.Equals(b.ID)
                                     select b.Titul).Single();
                        var autor = (from b in db.Books
                                     where l.Book_ID.Equals(b.ID)
                                     select b.Autor).Single();

                        mailBody = mailBody.Replace("##Title##", titul.ToString());
                        mailBody = mailBody.Replace("##Author##", autor.ToString());

                        message.Body = mailBody;

                        ms.SendMail(l.User_ID, message);

                        //mail to admin
                        mailBody = File.ReadAllText(adminFileName);

                        var user = (from u in db.AspNetUsers
                                    where l.User_ID.Equals(u.Id)
                                    select u).Single<AspNetUser>();

                        mailBody = mailBody.Replace("##Name##", user.FirstName);
                        mailBody = mailBody.Replace("##Surname##", user.LastName);
                        mailBody = mailBody.Replace("##User##", user.Email);
                        mailBody = mailBody.Replace("##Title##", titul.ToString());
                        mailBody = mailBody.Replace("##Author##", autor.ToString());

                        MailMessage adminMessage = new MailMessage("*****@*****.**", "*****@*****.**");

                        adminMessage.Body = mailBody;
                        adminMessage.Subject= "Scifiknihovna.cz - Nevrácená kniha.";
                        adminMessage.ReplyToList.Add(user.Email);

                        SmtpClient client=new SmtpClient();
                        client.Send(adminMessage);

                    }
                }

                //delete expiring reservations
                if (expReservations.Count != 0)
                {
                    var resMan = new ReservationManager(db);
                    foreach (Reservation r in expReservations)
                    {
                        resMan.DeleteReservation(r.Id);
                    }
                }

            }
        }