public ActionResult Add()
        {
            Site_MaillingListTemplate model = new Site_MaillingListTemplate();

            return(View(model));
        }
        public ActionResult Update(Site_MaillingListTemplate model, IEnumerable <HttpPostedFileBase> FileUp, string IsPublic, string Status)
        {
            model.IsPublic = IsPublic != null ? true : false;
            model.Status   = Status != null ? true : false;

            if (string.IsNullOrEmpty(model.Name))
            {
                return(JsonError("Please enter template name"));
            }

            if (string.IsNullOrEmpty(model.Body))
            {
                return(JsonError("Please enter template body"));
            }


            Site_MaillingListTemplate current_item = new Site_MaillingListTemplate();

            if (model.Id > 0)
            {
                var z = Db.Where <Site_MaillingListTemplate>(m => m.Id == model.Id);
                if (z.Count == 0)
                {
                    // the ID is not exist
                    return(JsonError("Please dont try to hack us"));
                }
                else
                {
                    current_item = z.First();
                }
            }

            // generate seo name
            string random = "";

            do
            {
                if (string.IsNullOrEmpty(model.Systemname))
                {
                    model.Systemname = model.Name + random;
                    model.Systemname = model.Systemname.ToSeoUrl();
                }
                else
                {
                    model.Systemname = model.Systemname.ToSeoUrl();
                }

                // check exist
                if (Db.Count <Site_MaillingListTemplate>(m => m.Systemname == model.Systemname && m.Id != model.Id) == 0)
                {
                    break;
                }

                random           = "_" + random.GenerateRandomText(3);
                model.Systemname = "";
            } while (0 < 1);

            if (model.Id == 0)
            {
                model.CreatedOn = DateTime.Now;
                model.CreatedBy = AuthenticatedUserID;
            }
            else
            {
                model.CreatedOn = current_item.CreatedOn;
                model.CreatedBy = current_item.CreatedBy;
            }

            if (model.Id == 0)
            {
                Db.Insert <Site_MaillingListTemplate>(model);
            }
            else
            {
                Db.Update <Site_MaillingListTemplate>(model);
            }

            return(JsonSuccess(Url.Action("Index")));
        }
Esempio n. 3
0
        static void Execute()
        {
            while (thread.IsAlive)
            {
                try
                {
                    int interval = (int)Settings.Get(Enum_Settings_Key.TASK_AUTO_CANCEL_ORDER_IF_MORETHAN_MINUTE, 5, Enum_Settings_DataType.Int);

                    Site_MaillingListTemplate template = Get_MaillingListTemplate("cancel_order_not_receive_payment");
                    if (template == null)
                    {
                        thread.Abort();
                        break;
                    }

                    var orders = Db.Select <Order>(x => x.Where(y => (
                                                                    y.Status == (int)Enum_OrderStatus.Received &&
                                                                    !y.Payment_isPaid &&
                                                                    y.PaymentStatus != (int)Enum_PaymentStatus.Paid &&
                                                                    DateTime.Now.Subtract(TimeSpan.FromMinutes(interval)) > y.CreatedOn)));

                    foreach (var order in orders)
                    {
                        // set status to cancel
                        order.Status = (int)Enum_OrderStatus.Canceled;

                        Db.UpdateOnly <Order>(order, ev => ev.Update(p => new
                        {
                            p.Status
                        }).Where(m => (m.Id == order.Id)).Limit(1));

                        order.AddHistory("Auto cancel order because of not receive payment", "System", 0, true);

                        #region Return The Coupon

                        if (order.isUseCoupon)
                        {
                            var coupon = Db.Select <CouponPromo>(x => x.Where(y => y.Code == order.Coupon_Code).Limit(1)).FirstOrDefault();

                            if (coupon != null)
                            {
                                Db.UpdateOnly <CouponPromo>(new CouponPromo()
                                {
                                    Used = coupon.Used - 1
                                }, ev => ev.Update(p => new { p.Used }).Where(m => m.Id == coupon.Id).Limit(1));

                                order.AddHistory(string.Format("Update coupon {0}, set used count from {1} to {2} ", coupon.Code, coupon.Used, coupon.Used - 1), "System", 0, true);
                            }
                        }

                        #endregion

                        #region Delete Photobook File

                        if (!order.Order_Photobook_Deleted)
                        {
                            var path = "";

                            if (order.PaymentStatusEnum == Enum_PaymentStatus.Paid)
                            {
                                path = Settings.Get(Enum_Settings_Key.WEBSITE_UPLOAD_PATH_DEFAULT, System.IO.Path.GetTempPath(), Enum_Settings_DataType.String).ToString();
                            }
                            else
                            {
                                path = Settings.Get(Enum_Settings_Key.WEBSITE_ORDERS_FOLDER_NOTYETPAID_PATH, System.IO.Path.GetTempPath(), Enum_Settings_DataType.String).ToString();
                            }

                            path = System.IO.Path.Combine(path, order.Order_Number);

                            if (System.IO.Directory.Exists(path))
                            {
                                try
                                {
                                    System.IO.Directory.Delete(path, true);

                                    order.AddHistory("Deleted photobook folder in " + path, "System", 0, true);

                                    Db.UpdateOnly <Order>(new Order()
                                    {
                                        Order_Photobook_Deleted = true
                                    }, ev => ev.Update(p => new { p.Order_Photobook_Deleted }).Where(m => m.Id == order.Id).Limit(1));
                                }
                                catch (Exception ex)
                                {
                                    order.AddHistory("Error while deleting photobook folder: " + ex.Message, "System", 0, true);
                                }
                            }
                            else
                            {
                                order.AddHistory("Warning: System can not find photobook folder in " + path, "System", 0, true);
                            }
                        }

                        #endregion

                        #region Send Email For Customer

                        Dictionary <string, string> dic = order.GetPropertiesListOrValue(true, "");
                        order.LoadAddress(0);
                        order.LoadAddress(1);
                        order.LoadProductInfo();
                        var billing  = order.BillingAddressModel.GetPropertiesListOrValue(true, "Billing_");
                        var shipping = order.BillingAddressModel.GetPropertiesListOrValue(true, "Shipping_");
                        dic = dic.MergeDictionary(billing);
                        dic = dic.MergeDictionary(shipping);

                        if (template != null)
                        {
                            var content = template.Body;
                            var title   = template.Title;
                            SendMail_RenderBeforeSend(ref content, ref title, dic);

                            //order.Customer_Email
                            PhotoBookmart.Common.Helpers.SendEmail.SendMail(order.Customer_Email, title, content, "*****@*****.**", "Photobookmart Customer Support");

                            order.AddHistory(string.Format("<b>Send message to customer</b>\r\nTitle: {0}\r\nContent:{1}", title, content), "System", 0, true);
                        }

                        #endregion
                    }
                    Db.Close();
                }
                catch (Exception ex)
                {
                    server_client = null;

                    if (ex.Message != "Thread was being aborted")
                    {
                        InsertException(ex.Message, ex);
                    }
                }

                Thread.Sleep(1000 * 60 * 5);
            }
        }