Ejemplo n.º 1
0
        public ActionResult SendEmail(CustomerEmailModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var customer = db.Patients.Where(o => o.Email == model.Email).FirstOrDefault();

            //EmailExtensions.SendMail(model.Email, model.Subject, model.Body);

            EmailExtensions.SendSms(customer.ContactNumber, model.Body);

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 2
0
        public ActionResult ChangeOrderStatus(int orderId, int statusId)
        {
            var order  = db.CustomerOrders.Find(orderId);
            var status = db.OrderStatuses.Find(statusId);

            order.OrderStatusId = statusId;
            order.OrderStatus   = status;

            db.Entry(order).State = System.Data.Entity.EntityState.Modified;

            db.Notifications.PushNotificaiton(string.Format("You changed Customer Order #{0} status", orderId));


            db.SaveChanges();

            //EmailExtensions.SendMail(order.Email, "Doctor J Govender: Order #" + order.Id,
            //    "Order Status changed to " + status.Name);

            EmailExtensions.SendSms(order.PhoneNumber, "Doctor J Govender: Order #" + order.Id + "Order Status changed to " + status.Name);

            return(RedirectToAction("Index"));
        }
        public ActionResult Complete(int?id)
        {
            var orderId   = Convert.ToInt32(Session["CustomerOrderId"]);
            var orderId1  = customerOrderRepository.GetOrderId(this.HttpContext);
            var patientId = Convert.ToInt32(Session["id"]);

            var order   = db.CustomerOrders.Find(orderId1);
            var patient = db.Patients.Find(patientId);

            string status = "Unknown";

            switch (id.ToString())
            {
            case "-2":
                status = "Unable to reconsile transaction";
                break;

            case "-1":
                status = "Checksum Error. The values have been altered";
                break;

            case "0":
                status = "Not Done";
                break;

            case "1":
                //status = "Approved";
                status = customerOrderRepository.PaymentApproved(this.HttpContext);
                break;

            case "2":
                //status = "Declined";
                status = customerOrderRepository.PaymentDeclined(this.HttpContext);

                break;

            case "3":
                status = "Cancelled";
                break;

            case "4":
                status = "User Cancelled";
                break;

            default:
                status = $"Unknown Status({ id })";
                break;
            }
            TempData["Status"] = status;

            if (status == "Approved")
            {
                var callbackUrl = Url.Action("view-order", "order", new { area = "store", id = order.Id }, protocol: Request.Url.Scheme);
                var loyaltyLink = Url.Action("Subscribe", "Loyalties", new { patientId = order.Customer.UserID });

                //EmailExtensions.SendMail(order.Email, "Doctor J Govender Pharmacy: Thank you for you Purchase!",
                //    string.Format("<h1><strong>Hello {0}</strong></h1> <br><br>" +
                //                  "Thank you for your recent transaction on our Pharmacy." +
                //                  "If you are new to our store and not a loyalty member, you can sign up for free for rewards.<br><br>" +
                //    "Your order has being successfully approved and is being processed.<br>" +
                //    "<a href=\"" + callbackUrl + "\">View Order Here</a></strong>", order.Customer.FirstName));

                //EmailExtensions.SendSms(order.Email, "Doctor J Govender Pharmacy: Thank you for you Purchase! Your order has being successfully approved and is being processed." + callbackUrl);
                EmailExtensions.SendSms(order.PhoneNumber, "Doctor J Govender Pharmacy: Thank you for your purchase! Total R" + order.TotalCost);

                //var client = new Client(creds: new Nexmo.Api.Request.Credentials
                //{
                //    ApiKey = "0f48d10b",
                //    ApiSecret = "R0hfbIdGjgNcG9Aa"
                //});

                //var results = client.SMS.Send(request: new SMS.SMSRequest
                //{
                //    from = "Dr J Govender",
                //    to = order.PhoneNumber,
                //    text = "Doctor J Govender Pharmacy: Thank you for you Purchase!"
                //});

                db.Notifications.PushNotificaiton(string.Format("A Customer placed an order: #{0}", order.Id));

                if (patient.isLoyal)
                {
                    var loyalty = db.Loyalties.Where(l => l.PatientId == patientId).FirstOrDefault();
                    var prefs   = db.LoyaltyPreferences.FirstOrDefault();

                    loyalty.Loyalty_Points += 25;

                    if (loyalty.Loyalty_Points >= prefs.PointsLimit)
                    {
                        db.Coupons.Add(new PharmacyEntities.Coupon
                        {
                            isLoyaltyCoupon = true,
                            Code            = string.Format("{0}-{1}-{2}", prefs.CouponCode, patient.UserID, order.Id),
                            Description     = "Loyalty Coupon",
                            EndDate         = DateTime.Now.AddMonths(prefs.MonthsToExpiry),
                            StartDate       = DateTime.Today,
                            DiscountRate    = prefs.CouponDiscountRate,
                            Active          = true,
                            Display         = false
                        });

                        db.SaveChanges();

                        var coup = db.Coupons.OrderByDescending(c => c.Id).FirstOrDefault();

                        //EmailExtensions.SendMail(patient.Email, prefs.Subject,
                        //    string.Format("<h1 class='text-center'>Code: {0}-{1}-{2}</h1> <br><br>" +
                        //                  "Valid until {3}<br>" +
                        //                  "Discount Rate: {4}%" +
                        //                  "{5}", prefs.CouponCode, patient.UserID, order.Id, coup.EndDate.ToLongDateString(), coup.DiscountRate, prefs.Body));


                        EmailExtensions.SendSms(patient.ContactNumber, string.Format(prefs.Subject + "Code: {0}-{1}-{2} . Valid until {3}. Discount Rate: {4}%", prefs.CouponCode, patient.UserID, order.Id, coup.EndDate.ToLongDateString(), coup.DiscountRate));
                        loyalty.Loyalty_Points = 0;
                    }
                    db.Entry(loyalty).State = System.Data.Entity.EntityState.Modified;
                }

                db.SaveChanges();
            }

            return(View());
        }
Ejemplo n.º 4
0
        public async Task <ActionResult> CreateOrder(NewPurchaseVM model)
        {
            if (ModelState.IsValid)
            {
                Supplier supplier = db.Suppliers.Find(model.SupplierId);

                // Change order status
                OrderStatus defaultOrderStatus = await db.OrderStatuses.Where(os => os.ProcessNumber == 2)
                                                 .FirstOrDefaultAsync();

                // Cant buy stock if theres no items in the cart
                if (!db.StockCarts.Any(c => c.SupplierId == model.SupplierId))
                {
                    TempData["Error"] = "There is no items in the cart to place order.";
                    return(Redirect("/Pharmacist/StockOrders/NewPurchase?supplierId=" + model.SupplierId));
                }

                db.StockOrders.Add(new StockOrder
                {
                    SupplierId     = model.SupplierId,
                    PaymentPeriod  = model.PaymentPeriod,
                    StockOrderDate = DateTime.Now,
                    TotalCost      = model.TotalPrice,
                    Notes          = model.Notes,
                    SubTotal       = model.SubTotal,
                    TotalTax       = model.TaxTotal,
                    Supplier       = supplier,
                    OrderStatusId  = defaultOrderStatus.Id,
                    OrderStatus    = defaultOrderStatus
                });

                await db.SaveChangesAsync();

                // Assign orderid to stockcart items
                var stockCart = await db.StockCarts.Where(c => c.StockOrderId.Equals(null)).ToListAsync();

                var latestOrder = await db.StockOrders.OrderByDescending(o => o.Id).FirstAsync();

                stockCart.ForEach(c => c.StockOrderId = latestOrder.Id); // Order Id Should Equal to the latest order

                // Add notification
                db.Notifications.Add(new Notification
                {
                    CreatedDate         = DateTime.Now,
                    Message             = "You have placed an order of R" + latestOrder.TotalCost,
                    isRead              = false,
                    Icon                = "fa-file-alt",
                    BackgroundColorIcon = "bg-info"
                });

                await db.SaveChangesAsync();

                var callbackUrl = Url.Action("InvoiceToPdf", "StockOrders", new { area = "pharmacist", id = latestOrder.Id }, protocol: Request.Url.Scheme);

                //EmailExtensions.SendMail(supplier.Email, "Request For A Stock Order",
                //    string.Format("Good day. <br><br>I would like to request a stock order of R{0}.<br><br>" +
                //    "<a href=\"" + callbackUrl + "\">Review Order Details Here</a><br><br>" +
                //    "<strong>Order Notes: <strong><br>" +
                //    "{2}", latestOrder.TotalCost, latestOrder.Id, latestOrder.Notes));

                EmailExtensions.SendSms(supplier.ContactNumber,
                                        string.Format("From Dr J Govender Practice: Good day. I would like to request a stock order of R{0}. " +
                                                      "Order Notes: {1}", latestOrder.TotalCost, latestOrder.Notes));

                return(RedirectToAction("Index"));
            }
            return(View(model));
        }