Beispiel #1
0
        public JsonResult Create(CMS_OrderAdminModels Order)
        {
            var status = 200;

            try
            {
                var model = new CMS_CheckOutModels
                {
                    CreatedUser  = CurrentUser.UserId,
                    ModifiedUser = CurrentUser.UserId,
                    Customer     = new CMS_DTO.CMSCustomer.CMS_CustomerAnonymousModels
                    {
                        Address     = Order.Address,
                        City        = Order.City,
                        Company     = Order.Company,
                        Country     = Order.Country,
                        Description = Order.Description,
                        Email       = Order.Email,
                        FirstName   = Order.FirstName,
                        LastName    = Order.LastName,
                        Phone       = Order.Phone,
                        Id          = Order.Id
                    },
                    TotalPrice    = Order.TotalPrice,
                    TotalDiscount = Order.TotalDiscount,
                    SubTotalPrice = Order.SubTotal,
                    ListItem      = Order.Items,
                    IsTemp        = false //admin
                };
                if (model != null && model.ListItem != null && model.ListItem.Any() && !string.IsNullOrEmpty(Order.DiscountID))
                {
                    model.ListItem.Add(new CMS_ItemModels
                    {
                        DiscountID    = Order.DiscountID,
                        DiscountType  = Order.DiscountType,
                        DiscountValue = Order.DiscountValue
                    });
                }
                var OrderId = string.Empty;
                var result  = _fac.CreateOrder(model, ref OrderId);
                if (!result)
                {
                    status = 500;
                }
            }
            catch (Exception ex)
            {
                NSLog.Logger.Error("Create_Error : ", ex);
            }
            var obj = new
            {
                Status = status,
            };

            return(Json(obj, JsonRequestBehavior.AllowGet));
        }
        public JsonResult Create(CMS_OrderAdminModels Order)
        {
            var status = 200;

            try
            {
                var model = new CMS_CheckOutModels
                {
                    CreatedUser  = CurrentUser.UserName,
                    ModifiedUser = CurrentUser.UserName,
                    Customer     = new CMS_DTO.CMSCustomer.CMS_CustomerAnonymousModels
                    {
                        Address     = Order.Address,
                        City        = Order.City,
                        Company     = Order.Company,
                        Country     = Order.Country,
                        Description = Order.Description,
                        Email       = Order.Email,
                        FirstName   = Order.FirstName,
                        LastName    = Order.LastName,
                        Phone       = Order.Phone,
                        Id          = Order.Id
                    },
                    ListItem   = Order.Items,
                    OrderType  = (byte)CMS_Common.Commons.EOrderType.Expense,
                    TotalPrice = Order.Items != null?Order.Items.Sum(o => o.TotalPrice) : 0,
                                     SubTotalPrice = Order.Items != null?Order.Items.Sum(o => o.TotalPrice) : 0,
                                                         IsTemp = false //admin
                };
                var OrderId = string.Empty;
                var result  = _fac.CreateOrder(model, ref OrderId);
                if (!result)
                {
                    status = 500;
                }
            }
            catch (Exception ex)
            {
                NSLog.Logger.Error("Create_Error : ", ex);
            }
            var obj = new
            {
                Status = status,
            };

            return(Json(obj, JsonRequestBehavior.AllowGet));
        }
Beispiel #3
0
        public ActionResult CheckOut(CMS_CheckOutModels model)
        {
            try
            {
                var _Orders = GetListOrderCookie();
                NSLog.Logger.Info("List Order Cookie", JsonConvert.SerializeObject(_Orders));
                if (_Orders != null && _Orders.Any())
                {
                    var ItemIds = _Orders.Select(x => x.ItemId).ToList();
                    var data    = _fac.GetList().Where(o => ItemIds.Contains(o.Id))
                                  .Select(o => new CMS_ItemModels
                    {
                        Price       = o.ProductPrice,
                        ProductID   = o.Id,
                        ProductName = o.ProductName,
                        Quantity    = o.Quantity
                    }).ToList();
                    if (data != null && data.Any())
                    {
                        data.ForEach(o =>
                        {
                            var item     = _Orders.FirstOrDefault(z => z.ItemId.Equals(o.ProductID));
                            o.Quantity   = item.Quantity;
                            o.TotalPrice = Convert.ToDouble(o.Price * item.Quantity);
                        });
                        model.ListItem = data;

                        model.TotalPrice    = data.Sum(o => o.TotalPrice);
                        model.SubTotalPrice = data.Sum(o => o.TotalPrice);

                        if (!string.IsNullOrEmpty(model.DiscountID))
                        {
                            model.ListItem.Add(new CMS_ItemModels
                            {
                                DiscountID    = model.DiscountID,
                                DiscountType  = model.DiscountType,
                                DiscountValue = model.DiscountValue
                            });

                            if (model.DiscountType == (byte)CMS_Common.Commons.EValueType.Percent)
                            {
                                model.TotalDiscount = CommonHelper.RoundingOption4(model.TotalPrice * (model.DiscountValue / 100));
                            }
                            else
                            {
                                model.TotalDiscount = model.DiscountValue;
                            }
                            model.TotalPrice = CommonHelper.RoundingOption4(model.TotalPrice - model.TotalDiscount);
                        }
                    }
                    var OrderId = string.Empty;
                    var result  = _facOrder.CreateOrder(model, ref OrderId);
                    if (result)
                    {
                        //get info order
                        if (!string.IsNullOrEmpty(OrderId))
                        {
                            var modelOrder = new CMS_OrderModels();
                            modelOrder = _facOrder.GetDetailOrder(OrderId);
                            //body mail
                            var body    = CommonHelper.CreateBodyMail(modelOrder);
                            var subject = "[V/v đơn hàng " + modelOrder.OrderNo + "]";
                            //Send to admin
                            CommonHelper.SendContentMail(ConfigurationManager.AppSettings["LamodeMail"], body, "", subject, "", "");
                            //Send to customer
                            CommonHelper.SendContentMail(modelOrder.Email, body, "", subject, "", "");
                        }
                        HttpCookie currentUserCookie = HttpContext.Request.Cookies["cms-order"];
                        HttpContext.Response.Cookies.Remove("cms-order");
                        currentUserCookie.Expires = DateTime.Now.AddDays(-10);
                        currentUserCookie.Value   = null;
                        HttpContext.Response.SetCookie(currentUserCookie);
                        return(RedirectToAction("Index", "Home"));
                    }
                    else
                    {
                        model.IsError = true;
                    }
                }
            }
            catch (Exception ex)
            {
                NSLog.Logger.Error("CheckOut", ex);
            }
            return(View(model));
        }