public ActionResult ReminderPreview(ReminderJSON reminder)
        {
            var template = db.fees_templates.SingleOrDefault(x => x.id == reminder.templateid);

            if (template == null)
            {
                return(SendJsonErrorResponse("Template not found"));
            }

            var viewmodel = new Reminder();

            viewmodel.Initialise(reminder);

            var liquid = new LiquidTemplate(template.body);

            liquid.AddParameters("reminder", viewmodel);

            var view = liquid.Render();

            return(Json(view.ToJsonOKData()));
        }
        public ActionResult ReminderSend(ReminderJSON reminder)
        {
            var template = db.fees_templates.SingleOrDefault(x => x.id == reminder.templateid);

            if (template == null)
            {
                return(SendJsonErrorResponse("Template not found"));
            }

            var viewmodel = new Reminder();

            viewmodel.Initialise(reminder);

            var parent = repository.GetUser(reminder.parentid);

            if (parent == null)
            {
                return(SendJsonErrorResponse("Could not locate parent"));
            }

            if (reminder.useEmail && string.IsNullOrEmpty(parent.email))
            {
                return(SendJsonErrorResponse("Selected parent has no email address. Select another parent."));
            }

            if (reminder.useSMS && string.IsNullOrEmpty(parent.phone_cell))
            {
                return(SendJsonErrorResponse("Selected parent has no cell phone number. Select another parent."));
            }

            if (reminder.useEmail)
            {
                var liquid = new LiquidTemplate(template.body);
                liquid.AddParameters("reminder", viewmodel);

                var emailbody = liquid.Render();

                new Thread(() => Email.SendMail(" School", "*****@*****.**", parent.ToName(false), parent.email, template.title, emailbody, false, null)).Start();
            }

            // save reminder params into db
            foreach (var feeid in reminder.children.SelectMany(x => x.feeids))
            {
                var dbentry = new fees_reminder();
                dbentry.templatename = template.title;
                dbentry.created      = DateTime.UtcNow;
                dbentry.paymentdue   = reminder.date_due;
                dbentry.receiver     = parent.id;
                dbentry.sender       = sessionid.Value;
                dbentry.feeid        = feeid;
                dbentry.uniqueid     = viewmodel.uniqueid;
                db.fees_reminders.InsertOnSubmit(dbentry);
            }


            repository.Save();

            // return view
            var view = this.RenderViewToString("Alerts",
                                               new[]
            {
                new LateFeeAlertSiblings(
                    reminder.children.Select(x => x.studentid))
            }).ToJsonOKData();

            view.message = "Reminder sent successfully";

            return(Json(view));
        }
Beispiel #3
0
        protected LiquidTemplate CreateLiquidTemplate(string templateName, string page_title)
        {
            var template = new LiquidTemplate(MASTERdomain, (bool)Session[BrowserCapability.IsMobileSession]);
            template.InitLayoutTemplate("layout/theme.liquid");
            if (!string.IsNullOrEmpty(page_title))
            {
                template.AddParameters("page_title", page_title);
            }
            template.AddParameters("template", templateName);
            template.AddParameters("linklists", new LinkLists(MASTERdomain));
            template.AddParameters("pages", new Pages(MASTERdomain));
            template.AddParameters("blogs", new Blogs(MASTERdomain));
            template.AddParameters("collections", new Collections(MASTERdomain, sessionid));
            template.AddParameters("powered_by_link", "<a href='http://www.tradelr.com'>This online store is powered by tradelr</a>");

            // settings
            var settings_file = string.Format("{0}/{1}/config/settings_data.json", GeneralConstants.APP_ROOT_DIR, template.handler.GetThemeUrl());
            template.AddParameters("settings", template.ReadThemeSettings(settings_file));

            // cart
            var cartid = GetCartIdFromCookie();
            var liquidCart = new Cart();
            if (!string.IsNullOrEmpty(cartid))
            {
                var cart = MASTERdomain.carts.SingleOrDefault(x => x.id.ToString() == cartid);
                if (cart != null)
                {
                    if (cart.orderid.HasValue)
                    {
                        // cart already processed. clear cookie
                        Response.Cookies["cart"].Expires = DateTime.UtcNow.AddMonths(-1);
                    }
                    else
                    {
                        liquidCart = cart.ToLiquidModel(sessionid);
                    }
                }
            }
            template.AddParameters("cart", liquidCart);
            template.AddParameters("shop", MASTERdomain.ToLiquidModel());

            template.AddHeaderContent(MASTERdomain.metaTagVerification);

            // login panel
            template.AddParameters("login_for_store",
                                   this.RenderViewToString("~/Views/store/liquid/loginPanel.ascx",
                                                           new LoginPanel()
                                                               {
                                                                   isLoggedIn =sessionid.HasValue,
                                                                   hostName = accountHostname.ToDomainUrl()
                                                               }));
            // add filters
            // currency
            var currency = MASTERdomain.currency.ToCurrency();
            template.AddFilterValues("currency", currency);

            // add registers
            template.AddRegisters("current_url", Request.Url);

            // add term form date
            if (TempData["form"] != null)
            {
                template.AddParameters("posted_contact_form", TempData["form"]);
            }

            return template;
        }