Ejemplo n.º 1
0
        public async Task <ActionResult> EditDelivery(PublicationDeliveryModel model)
        {
            if (ModelState.IsValid)
            {
                var response_delivery = await WepApiMethod.SendApiAsync <bool>(HttpVerbs.Post, $"RnP/Publication/UpdateDeliveryInfo", model);

                if (!response_delivery.isSuccess)
                {
                    return(HttpNotFound());
                }

                return(RedirectToAction("Review", "Cart", new { area = "Commerce" }));
            }

            return(View(model));
        }
Ejemplo n.º 2
0
        public async Task <string> AddToCart(PurchasePublicationModel model)
        {
            if (ModelState.IsValid)
            {
                // get publication info (use fresh price)
                var resPub = await WepApiMethod.SendApiAsync <ReturnPublicationModel>(HttpVerbs.Get, $"RnP/Publication?id={model.PublicationID}");

                if (!resPub.isSuccess)
                {
                    return("notfound");
                }

                var publication = resPub.Data;

                if (publication == null)
                {
                    return("notfound");
                }

                // create cart
                var order = new PurchaseOrderModel
                {
                    UserId            = CurrentUser.UserId.Value,
                    DiscountCode      = "",
                    ProformaInvoiceNo = "",
                    PaymentMode       = PaymentModes.Online,
                    CreatedDate       = DateTime.Now,
                    TotalPrice        = 0,
                    Status            = CheckoutStatus.Shopping
                };

                var response_cart = await WepApiMethod.SendApiAsync <int>(HttpVerbs.Post, $"Commerce/Cart/Create", order);

                if (!response_cart.isSuccess)
                {
                    return("notfound");
                }

                var cartid = response_cart.Data;

                var addsuccess = true;

                // add items to cart
                if (model.FormatDigital)
                {
                    var ditem1 = new PublicationPurchaseItemModel
                    {
                        PurchaseOrderId = cartid,
                        PublicationID   = publication.ID,
                        UserId          = CurrentUser.UserId.Value,
                        Format          = PublicationFormats.Digital,
                        Price           = publication.DPrice,
                        Quantity        = 1
                    };
                    var response_digital = await WepApiMethod.SendApiAsync <bool>(HttpVerbs.Post, $"RnP/Publication/AddOrderItem", ditem1);

                    var citem1 = new PurchaseOrderItemModel
                    {
                        PurchaseOrderId = cartid,
                        ItemId          = publication.ID,
                        Description     = publication.Title + " (Digital)",
                        PurchaseType    = PurchaseType.Publication,
                        Price           = publication.DPrice,
                        Quantity        = 1
                    };
                    var cart_digital = await WepApiMethod.SendApiAsync <bool>(HttpVerbs.Post, $"Commerce/Cart/AddItem", citem1);
                }

                if (model.FormatHardcopy)
                {
                    var ditem2 = new PublicationPurchaseItemModel
                    {
                        PurchaseOrderId = cartid,
                        PublicationID   = publication.ID,
                        UserId          = CurrentUser.UserId.Value,
                        Format          = PublicationFormats.Hardcopy,
                        Price           = publication.HPrice,
                        Quantity        = model.HardcopyQuantity
                    };
                    var response_hardcopy = await WepApiMethod.SendApiAsync <bool>(HttpVerbs.Post, $"RnP/Publication/AddOrderItem", ditem2);

                    var citem2 = new PurchaseOrderItemModel
                    {
                        PurchaseOrderId = cartid,
                        ItemId          = publication.ID,
                        Description     = publication.Title + " (Hard copy)",
                        PurchaseType    = PurchaseType.Publication,
                        Price           = publication.HPrice,
                        Quantity        = model.HardcopyQuantity
                    };
                    var cart_hardcopy = await WepApiMethod.SendApiAsync <bool>(HttpVerbs.Post, $"Commerce/Cart/AddItem", citem2);
                }

                if (model.FormatPromotion)
                {
                    var ditem3 = new PublicationPurchaseItemModel
                    {
                        PurchaseOrderId = cartid,
                        PublicationID   = publication.ID,
                        UserId          = CurrentUser.UserId.Value,
                        Format          = PublicationFormats.Promotion,
                        Price           = publication.HDPrice,
                        Quantity        = 1
                    };
                    var response_promotion = await WepApiMethod.SendApiAsync <bool>(HttpVerbs.Post, $"RnP/Publication/AddOrderItem", ditem3);

                    var citem3 = new PurchaseOrderItemModel
                    {
                        PurchaseOrderId = cartid,
                        ItemId          = publication.ID,
                        Description     = publication.Title + " (Promotion 1+1)",
                        PurchaseType    = PurchaseType.Publication,
                        Price           = publication.HDPrice,
                        Quantity        = 1
                    };
                    var cart_promotion = await WepApiMethod.SendApiAsync <bool>(HttpVerbs.Post, $"Commerce/Cart/AddItem", citem3);
                }

                // delivery address
                var deliverymodel = new PublicationDeliveryModel
                {
                    UserId      = CurrentUser.UserId.Value,
                    FirstName   = model.FirstName,
                    LastName    = model.LastName,
                    Address1    = model.Address1,
                    Address2    = model.Address2,
                    Postcode    = model.Postcode,
                    City        = model.City,
                    State       = model.State,
                    PhoneNumber = model.PhoneNumber
                };

                var response_delivery = await WepApiMethod.SendApiAsync <bool>(HttpVerbs.Post, $"RnP/Publication/UpdateDeliveryInfo", deliverymodel);

                if (addsuccess)
                {
                    await LogActivity(Model.Modules.RnP, "Purchase Publication", publication);

                    return("success");
                }
                else
                {
                    return("failure");
                }
            }
            return("invalid");
        }