Ejemplo n.º 1
0
        public ActionResult Edit(order order, string[] totalProduct)
        {
            //var tem = db.orders.Find(order.ocid);

            db.Entry(order).State = EntityState.Modified;
            db.SaveChanges();
            if (totalProduct != null)
            {
                var listItem = totalProduct.ToList().Distinct().ToList();
                foreach (var item in listItem)
                {
                    var itemId         = int.Parse(item.Split('_')[0]);
                    var tblItem        = db.items.FirstOrDefault(x => x.ARTNO == itemId);
                    var tblOrderDetail = db.orderdetails.FirstOrDefault(x => x.itemId == itemId && x.ocid == order.ocid);
                    if (tblOrderDetail == null)
                    {
                        var tblOrder = new orderdetail
                        {
                            ocid         = order.ocid,
                            itemId       = itemId,
                            ocdetailqty  = int.Parse(item.Split('_')[1]),
                            ocdetailname = tblItem != null ? tblItem.ARTNAME : ""
                        };
                        db.orderdetails.Add(tblOrder);
                    }
                    else
                    {
                        tblOrderDetail.ocdetailqty     = int.Parse(item.Split('_')[1]);
                        db.Entry(tblOrderDetail).State = EntityState.Modified;
                    }
                }
            }

            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 2
0
        public bool SendTemplateEmail(string recepientEmail, string username, string key, string Subject, int type, ShoppingCart shoppingCart = null, order order = null)
        {
            bool t = false;
            //Type =1 MailOrder
            //Type =2 ForgetPass

            var    tblSetting = db.settings.FirstOrDefault(x => x.code == "MailToManager");
            string body       = string.Empty;
            var    activelink = "";

            if (type == 1)
            {
                if (!string.IsNullOrEmpty(username))
                {
                    var tble = "";
                    if (shoppingCart != null)
                    {
                        foreach (var item in shoppingCart.cartItem.ToList())
                        {
                            tble += "<tr><td>" + item.Name + "</td><td>" + item.Qty + "</td><td>Germany</td></tr>";
                        }
                    }

                    body = ViewRenderer.RenderPartialView("~/Views/Shared/Partial/_OrderSuccessTemplateMail.cshtml");
                    body = body.Replace("##name##", username);
                    body = body.Replace("##Table##", tble);
                    if (order != null)
                    {
                        var invoiceAdd      = "First Name: " + order.fname + "<br>" + "Last Name: " + order.lname + "<br>" + "Phone: " + order.phone + "<br>" + "Address: " + order.addr1 + "," + order.addr2 + "," + order.addr3;
                        var deliveryAddress = "First Name: " + order.d_fname + "<br>" + "Last Name: " + order.d_lname + "<br>" + "Phone: " + order.d_phone + "<br>" + "Address: " + order.d_addr1 + "," + order.d_addr2 + "," + order.d_addr3;
                        body = body.Replace("##COD##", order.payoption);
                        body = body.Replace("##CASH##", order.payoption);
                        body = body.Replace("##InvoiceAddress##", invoiceAdd);
                        body = body.Replace("##DeliveryAddress##", deliveryAddress);
                        body = body.Replace("##nameorder##", deliveryAddress);
                        body = body.Replace("##Order##", "#" + order.ocid + "" + DateTime.Now.Day);
                    }
                }
            }
            if (type == 3)
            {
                var tble = "";
                if (shoppingCart != null)
                {
                    foreach (var item in shoppingCart.cartItem.ToList())
                    {
                        tble += "<tr><td>" + item.Name + "</td><td>" + item.Qty + "</td><td>Germany</td></tr>";
                    }
                }

                recepientEmail = (tblSetting != null ? tblSetting.name : "*****@*****.**");
                body           = ViewRenderer.RenderPartialView("~/Views/Shared/Partial/_OrderSuccessTemplateMailMa.cshtml");
                body           = body.Replace("##name##", (tblSetting != null ? tblSetting.name : "*****@*****.**"));

                body = body.Replace("##Table##", tble);
                if (order != null)
                {
                    var invoiceAdd      = "First Name: " + order.fname + "<br>" + "Last Name: " + order.lname + "<br>" + "Phone: " + order.phone + "<br>" + "Address: " + order.addr1 + "," + order.addr2 + "," + order.addr3;
                    var deliveryAddress = "First Name: " + order.d_fname + "<br>" + "Last Name: " + order.d_lname + "<br>" + "Phone: " + order.d_phone + "<br>" + "Address: " + order.d_addr1 + "," + order.d_addr2 + "," + order.d_addr3;
                    body = body.Replace("##COD##", order.payoption);
                    body = body.Replace("##CASH##", order.payoption);
                    body = body.Replace("##InvoiceAddress##", invoiceAdd);
                    body = body.Replace("##DeliveryAddress##", deliveryAddress);
                    body = body.Replace("##nameorder##", username);
                    body = body.Replace("##Order##", "#" + order.ocid + "" + DateTime.Now.Day);
                }
            }
            if (type == 2)
            {
                var check = db.users.ToList().FirstOrDefault(x => x.email == recepientEmail.ToLower());
                if (check != null)
                {
                    body = ViewRenderer.RenderPartialView("~/Views/Shared/Partial/_ResetPassTemplateMail.cshtml");
                    body = body.Replace("##name##", username);
                }
            }
            t = Models.Helper.SendEmail("*****@*****.**", recepientEmail, Subject, body);


            return(t);
        }
Ejemplo n.º 3
0
        // GET: /Checkout/Create
        public ActionResult Create()
        {
            var order = new order();
            var user  = new AllLoggedUserInfo();

            if (Session["ShoppingCart"] == null)
            {
                return(RedirectToAction("UpdateCart", "Home"));
            }
            else
            {
                ShoppingCart cart = (ShoppingCart)Session["ShoppingCart"];
                if (cart.cartItem.Count == 0)
                {
                    return(RedirectToAction("UpdateCart", "Home"));
                }

                ViewBag.Cart = cart;
                if (Session["LoggedAccount"] == null)
                {
                    return(View());
                }
                else
                {
                    if (string.IsNullOrWhiteSpace(cart.paid_key))
                    {
                        user = (AllLoggedUserInfo)Session["LoggedAccount"];
                        var tblUser = db.users.Join(db.userdatas, us => us.Id, usdt => usdt.userid,
                                                    (us, usdt) => new AllModel {
                            tblUser = us, tblUserData = usdt
                        }).FirstOrDefault(x => x.tblUser.Id == user.user.Id);

                        if (tblUser != null)
                        {
                            if (tblUser.tblUser.Id == 7 || tblUser.tblUser.Id == 1)
                            {
                                order = new order();
                            }
                            else
                            {
                                order.fname      = tblUser.tblUserData.firstname;
                                order.lname      = tblUser.tblUserData.lasname;
                                order.email      = tblUser.tblUser.email;
                                order.phone      = tblUser.tblUserData.contact_phone;
                                order.d_fname    = tblUser.tblUserData.delivery_name;
                                order.d_phone    = tblUser.tblUserData.delivery_phone;
                                order.d_email    = tblUser.tblUserData.delivery_email;
                                order.d_addr1    = tblUser.tblUserData.delivery_address1;
                                order.d_postcode = tblUser.tblUserData.delivery_postcode;
                                order.d_country  = tblUser.tblUserData.delivery_contry;
                                order.b_fname    = tblUser.tblUserData.billing_name;
                                order.b_phone    = tblUser.tblUserData.billing_phone;
                                order.b_email    = tblUser.tblUserData.billing_email;
                                order.b_addr1    = tblUser.tblUserData.billing_address1;
                                order.b_postcode = tblUser.tblUserData.billing_poscode;
                                order.b_country  = tblUser.tblUserData.billing_country;
                            }
                        }
                    }
                    else
                    {
                        order = db.orders.FirstOrDefault(t => t.paid_key == cart.paid_key);
                        if (order == null)
                        {
                            order = new order();
                            user  = (AllLoggedUserInfo)Session["LoggedAccount"];
                            var tblUser = db.users.Join(db.userdatas, us => us.Id, usdt => usdt.userid,
                                                        (us, usdt) => new AllModel {
                                tblUser = us, tblUserData = usdt
                            }).FirstOrDefault(x => x.tblUser.Id == user.user.Id);

                            if (tblUser != null)
                            {
                                if (tblUser.tblUser.Id == 7 || tblUser.tblUser.Id == 1)
                                {
                                    order = new order();
                                }
                                else
                                {
                                    order.fname      = tblUser.tblUserData.firstname;
                                    order.lname      = tblUser.tblUserData.lasname;
                                    order.email      = tblUser.tblUser.email;
                                    order.phone      = tblUser.tblUserData.contact_phone;
                                    order.d_fname    = tblUser.tblUserData.delivery_name;
                                    order.d_phone    = tblUser.tblUserData.delivery_phone;
                                    order.d_email    = tblUser.tblUserData.delivery_email;
                                    order.d_addr1    = tblUser.tblUserData.delivery_address1;
                                    order.d_postcode = tblUser.tblUserData.delivery_postcode;
                                    order.d_country  = tblUser.tblUserData.delivery_contry;
                                    order.b_fname    = tblUser.tblUserData.billing_name;
                                    order.b_phone    = tblUser.tblUserData.billing_phone;
                                    order.b_email    = tblUser.tblUserData.billing_email;
                                    order.b_addr1    = tblUser.tblUserData.billing_address1;
                                    order.b_postcode = tblUser.tblUserData.billing_poscode;
                                    order.b_country  = tblUser.tblUserData.billing_country;
                                }
                            }
                        }
                    }
                }
            }
            ViewBag.ListCountry = db.countries.ToList();
            return(View(order));
        }
Ejemplo n.º 4
0
        public ActionResult Create(order order, int?checkBilldingShipping)
        {
            if (ModelState.IsValid)
            {
                if (Session["ShoppingCart"] == null)
                {
                    return(RedirectToAction("UpdateCart", "Home"));
                }
                else
                {
                    try
                    {
                        var oldPriceOrder = 0.0;
                        if (order.ocid > 0)
                        {
                            var _order = db.orders.Where(t => t.ocid == order.ocid).FirstOrDefault();
                            oldPriceOrder          = _order.paid_amount.HasValue ? _order.paid_amount.Value : 0;
                            db.Entry(_order).State = EntityState.Detached;
                            db.SaveChanges();
                        }
                        order.d_companyname = string.IsNullOrEmpty(order.d_companyname) ? order.companyname : order.d_companyname;
                        order.d_fname       = string.IsNullOrEmpty(order.d_fname) ? order.fname : order.d_fname;
                        order.d_lname       = string.IsNullOrEmpty(order.d_lname) ? order.lname : order.d_lname;
                        order.d_email       = string.IsNullOrEmpty(order.d_email) ? order.email : order.d_email;
                        order.d_phone       = string.IsNullOrEmpty(order.d_phone) ? order.phone : order.d_phone;
                        order.d_addr1       = string.IsNullOrEmpty(order.d_addr1) ? order.addr1 : order.d_addr1;
                        if (checkBilldingShipping.HasValue && checkBilldingShipping.Value == 1)
                        {
                            order.b_companyname = string.IsNullOrEmpty(order.d_companyname) ? order.companyname : order.d_companyname;
                            order.b_fname       = string.IsNullOrEmpty(order.d_fname) ? order.fname : order.d_fname;
                            order.b_lname       = string.IsNullOrEmpty(order.d_lname) ? order.lname : order.d_lname;
                            order.b_email       = string.IsNullOrEmpty(order.d_email) ? order.email : order.d_email;
                            order.b_phone       = string.IsNullOrEmpty(order.d_phone) ? order.phone : order.d_phone;
                            order.b_addr1       = string.IsNullOrEmpty(order.d_addr1) ? order.addr1 : order.d_addr1;
                        }
                        order.status = "2";
                        if (order.payoption == "PayPal")
                        {
                            order.paid_status = 2;
                        }
                        if (order.payoption == "COD")
                        {
                            order.paid_status = 1;
                        }
                        ShoppingCart Cart = new ShoppingCart();
                        Cart = (ShoppingCart)Session["ShoppingCart"];
                        order.paid_amount = Cart.CartTotal + Cart.taxTotal;
                        String randomKey = Guid.NewGuid().ToString();
                        if (order.ocid == 0)
                        {
                            order.paid_key = randomKey;
                            db.orders.Add(order);
                            db.SaveChanges();
                        }
                        else
                        {
                            db.Entry(order).State = EntityState.Modified;
                            db.SaveChanges();
                        }

                        Cart.paid_key = order.paid_key;
                        WebApplication1.Models.AllLoggedUserInfo userFullInfo = (WebApplication1.Models.AllLoggedUserInfo)Session["LoggedAccount"];
                        if (userFullInfo != null)
                        {
                            var user = db.users.Find(userFullInfo.user.Id);
                            user.paidorder       = (user.paidorder ?? 0) + (decimal)Cart.CartTotal + (decimal)(order.feeshipping ?? 0) - (decimal)oldPriceOrder;
                            db.Entry(user).State = EntityState.Modified;
                            db.SaveChanges();
                        }
                        double       cartAmount   = 0;
                        string       currencyName = "USD";
                        ordersetting ordersetting = db.ordersettings.Where(t => t.status == 1).FirstOrDefault();
                        if (ordersetting != null)
                        {
                            currencyName = ordersetting.name;
                        }

                        var itemList = new ItemList();
                        var items    = new List <Item>();

                        String paypalURL    = "";
                        var    paypayconfig = new PayPalConfiguration();
                        var    apiContext   = paypayconfig.GetAPIContext();

                        var _orderdetails = db.orderdetails.Where(t => t.ocid == order.ocid).ToList();
                        var listItems     = _orderdetails.Select(t => t.ocdetailcode);
                        var _items        = db.items.Where(t => listItems.Contains(t.ARTCODE)).ToList();
                        foreach (var item in _orderdetails)
                        {
                            if (item.stockId.HasValue && item.stockId.Value > 0)
                            {
                                var _item = _items.FirstOrDefault(t => t.ARTCODE == item.ocdetailcode);
                                if (_item != null)
                                {
                                    var _stock = db.stocks.Where(t => t.ARTNO == item.itemId && t.STOCKNO == item.stockId).FirstOrDefault();
                                    _stock.VOLUME         += item.ocdetailqty.Value;
                                    db.Entry(_stock).State = EntityState.Modified;
                                }
                            }
                        }
                        db.orderdetails.RemoveRange(_orderdetails);
                        var _listItems = Cart.cartItem.Select(t => t.Code);
                        var __items    = db.items.Where(t => _listItems.Contains(t.ARTCODE)).ToList();
                        foreach (var item in Cart.cartItem)
                        {
                            orderdetail od = new orderdetail();
                            od.ocid          = order.ocid;
                            od.ocdetailcode  = item.Code;
                            od.ocdetailname  = item.Name;
                            od.ocdetailprice = item.Price;
                            od.ocdetailqty   = item.Qty;
                            od.ocdetailgst   = item.Tax / item.Qty;
                            od.stockId       = item.StockId;
                            if (item.StockId > 0)
                            {
                                var _item = __items.FirstOrDefault(t => t.ARTCODE == od.ocdetailcode);
                                if (_item != null)
                                {
                                    var _stock = db.stocks.Where(t => t.ARTNO == _item.ARTNO && t.STOCKNO == item.StockId).FirstOrDefault();
                                    _stock.VOLUME         -= item.Qty;
                                    db.Entry(_stock).State = EntityState.Modified;
                                    od.itemId = _item.ARTNO;
                                }
                            }
                            db.orderdetails.Add(od);

                            var Item = new Item();
                            Item.name     = item.Code + " - " + item.Name;
                            Item.currency = currencyName;

                            Item.price    = (item.Price + (item.Tax / item.Qty)) + "";
                            Item.quantity = item.Qty + "";
                            items.Add(Item);
                        }
                        if (order.feeshipping.HasValue && order.feeshipping.Value > 0)
                        {
                            var Item = new Item();
                            Item.name     = "Fee Shipping";
                            Item.currency = currencyName;
                            Item.price    = order.feeshipping + "";
                            Item.quantity = "1";
                            items.Add(Item);
                        }
                        if (Cart.promotion != null)
                        {
                            if (Cart.promotion.TYPENO == 0)
                            {
                                var Item = new Item();
                                Item.name     = "Discount Promotion";
                                Item.currency = currencyName;
                                Item.price    = "-" + Cart.PromotionTotal + "";
                                Item.quantity = "1";
                                items.Add(Item);
                            }
                        }
                        cartAmount     = Cart.CartTotal + Cart.taxTotal + order.feeshipping ?? 0;
                        cartAmount     = Math.Round(cartAmount, 2);
                        itemList.items = items;
                        db.SaveChanges();
                        if (order.payoption == "PayPal")
                        {
                            var payer = new Payer()
                            {
                                payment_method = "paypal"
                            };
                            var redirUrls = new RedirectUrls()
                            {
                                cancel_url = UrlHelper.Root + "Checkout/PayPalCancel?" + UrlHelper.ToQueryString(new { paid_key = order.paid_key }),
                                return_url = UrlHelper.Root + "Checkout/PayPalSuccess?" + UrlHelper.ToQueryString(new { paid_key = order.paid_key })
                            };
                            var paypalAmount = new Amount()
                            {
                                currency = currencyName, total = cartAmount.ToString()
                            };

                            var transactionList = new List <PayPal.Api.Transaction>();
                            PayPal.Api.Transaction transaction = new PayPal.Api.Transaction();
                            transaction.amount    = paypalAmount;
                            transaction.item_list = itemList;
                            transactionList.Add(transaction);


                            var payment = new Payment()
                            {
                                intent        = "Sale",
                                payer         = payer,
                                transactions  = transactionList,
                                redirect_urls = redirUrls
                            };

                            try
                            {
                                var createdPayment = payment.Create(apiContext);
                                var links          = createdPayment.links.GetEnumerator();
                                while (links.MoveNext())
                                {
                                    var link = links.Current;
                                    if (link.rel.ToLower().Trim().Equals("approval_url"))
                                    {
                                        paypalURL = link.href;
                                    }
                                }
                                return(Redirect(paypalURL));
                            }
                            catch (PaymentsException ex)
                            {
                                paypalURL = "ERROR: " + ex.Response;
                            }
                        }
                        else
                        {
                            SendTemplateEmail(order.d_email, order.d_email, "", "Order Success #" + order.ocid + "" + DateTime.Now.Day, 1, Cart, order);
                            SendTemplateEmail(order.d_email, order.d_email, "", "Order Success #" + order.ocid + "" + DateTime.Now.Day, 3, Cart, order);
                            return(RedirectToAction("Thankyou"));
                        }
                    }
                    catch (DbEntityValidationException e)
                    {
                        foreach (var eve in e.EntityValidationErrors)
                        {
                            Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                              eve.Entry.Entity.GetType().Name, eve.Entry.State);
                            foreach (var ve in eve.ValidationErrors)
                            {
                                Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                                  ve.PropertyName, ve.ErrorMessage);
                            }
                        }
                    }
                }
            }
            return(RedirectToAction("Create"));
        }