Пример #1
0
        public IHttpActionResult PutShippingMode(Guid id, ShippingMode shippingMode)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != shippingMode.ShippingMode_Id)
            {
                return(BadRequest());
            }

            db.Entry(shippingMode).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ShippingModeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #2
0
        public IHttpActionResult PostShippingMode(ShippingMode shippingMode)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.ShippingModes.Add(shippingMode);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (ShippingModeExists(shippingMode.ShippingMode_Id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = shippingMode.ShippingMode_Id }, shippingMode));
        }
Пример #3
0
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            ShippingMode shippingmode = await db.ShippingMode.FindAsync(id);

            db.ShippingMode.Remove(shippingmode);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Пример #4
0
        public IHttpActionResult GetShippingMode(Guid id)
        {
            ShippingMode shippingMode = db.ShippingModes.Find(id);

            if (shippingMode == null)
            {
                return(NotFound());
            }

            return(Ok(shippingMode));
        }
Пример #5
0
        public async Task <ActionResult> Edit([Bind(Include = "ShippingModeID,Updated,Updator,ShippingModeName,MeasurementID,Description")] ShippingMode shippingmode)
        {
            if (ModelState.IsValid)
            {
                db.Entry(shippingmode).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.MeasurementID = new SelectList(db.Measurement, "MeaurementID", "MeaurementName", shippingmode.MeasurementID);
            return(View(shippingmode));
        }
Пример #6
0
        public IHttpActionResult DeleteShippingMode(Guid id)
        {
            ShippingMode shippingMode = db.ShippingModes.Find(id);

            if (shippingMode == null)
            {
                return(NotFound());
            }

            db.ShippingModes.Remove(shippingMode);
            db.SaveChanges();

            return(Ok(shippingMode));
        }
Пример #7
0
        // GET: /ShippingMode/Details/5
        public async Task <ActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ShippingMode shippingmode = await db.ShippingMode.FindAsync(id);

            if (shippingmode == null)
            {
                return(HttpNotFound());
            }
            return(View(shippingmode));
        }
Пример #8
0
        // GET: /ShippingMode/Edit/5
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ShippingMode shippingmode = await db.ShippingMode.FindAsync(id);

            if (shippingmode == null)
            {
                return(HttpNotFound());
            }
            ViewBag.MeasurementID = new SelectList(db.Measurement, "MeaurementID", "MeaurementName", shippingmode.MeasurementID);
            return(View(shippingmode));
        }
Пример #9
0
        private void UpdateAddresses()
        {
            OrderInfo    order           = Order;
            IAddressInfo billingAddress  = BillingAddress;
            IAddressInfo shippingAddress = ShippingAddress;
            ShippingMode shipping        = Shipping;
            bool         updateOrder     = false;

            // Define the current user ID
            int currentUser = IsLogged ? UserId : StoreSettings.ImpersonatedUserID;

            // If the user state has changed
            if (order.CustomerID != currentUser)
            {
                updateOrder = true;
            }

            // If the billing address exist but linked to a different user (probably anonymous or impersonated)
            if (billingAddress.AddressID != Null.NullInteger && billingAddress.UserID != currentUser)
            {
                // If address was user saved, create a new one
                if (billingAddress.UserSaved)
                {
                    billingAddress.AddressID = Null.NullInteger;
                    billingAddress.UserSaved = false;
                }
                billingAddress.PrimaryAddress = false;
                billingAddress.UserID         = currentUser;
                billingAddress.Modified       = true;
                updateOrder = true;
            }

            // If the shipping address exist but linked to a different user (probably anonymous or impersonated)
            if (shippingAddress.AddressID != Null.NullInteger && shippingAddress.UserID != currentUser)
            {
                // If address was user saved, create a new one
                if (shippingAddress.UserSaved)
                {
                    shippingAddress.AddressID = Null.NullInteger;
                    shippingAddress.UserSaved = false;
                }
                shippingAddress.PrimaryAddress = false;
                shippingAddress.UserID         = currentUser;
                shippingAddress.Modified       = true;
                updateOrder = true;
            }

            // Add or update billing address
            int billingAddressID = billingAddress.AddressID;

            if ((billingAddressID == Null.NullInteger && billingAddress.Modified) || billingAddressID == 0)
            {
                billingAddress.PortalID = PortalId;
                billingAddress.UserID   = currentUser;
                if (string.IsNullOrEmpty(billingAddress.Description))
                {
                    billingAddress.Description = string.Format(Localization.GetString("BillingDescription", LocalResourceFile), order.OrderID);
                }
                billingAddressID = _addressProvider.AddAddress(billingAddress);
                BillingAddress   = _addressProvider.GetAddress(billingAddressID);
                if (shipping == ShippingMode.SameAsBilling)
                {
                    ShippingAddress = shippingAddress = BillingAddress;
                }
            }
            else if (billingAddressID != Null.NullInteger && billingAddress.Modified)
            {
                _addressProvider.UpdateAddress(billingAddress);
            }
            if (billingAddressID != Order.BillingAddressID)
            {
                updateOrder = true;
            }

            // Add or update shipping address
            int shippingAddressID = shippingAddress.AddressID;

            if (shipping != ShippingMode.None && shippingAddressID != billingAddressID)
            {
                if ((shipping == ShippingMode.Other && shippingAddressID == Null.NullInteger && shippingAddress.Modified) || shippingAddressID == 0)
                {
                    shippingAddress.PortalID = PortalId;
                    shippingAddress.UserID   = currentUser;
                    if (string.IsNullOrEmpty(shippingAddress.Description))
                    {
                        shippingAddress.Description = string.Format(Localization.GetString("ShippingDescription", LocalResourceFile), order.OrderID);
                    }
                    shippingAddressID = _addressProvider.AddAddress(shippingAddress);
                    ShippingAddress   = _addressProvider.GetAddress(shippingAddressID);
                }
                else if (shipping == ShippingMode.SameAsBilling && shippingAddressID != billingAddressID)
                {
                    shippingAddressID = billingAddressID;
                }
                else if (shippingAddressID != Null.NullInteger && shippingAddress.Modified)
                {
                    _addressProvider.UpdateAddress(shippingAddress);
                }
            }
            if (shippingAddressID != Order.ShippingAddressID)
            {
                updateOrder = true;
            }

            // Update order if needed
            if (updateOrder)
            {
                Order.BillingAddressID  = billingAddressID;
                Order.ShippingAddressID = shippingAddressID;
                _orderController.UpdateOrder(order.OrderID, order.OrderDate, order.OrderNumber, shippingAddressID,
                                             billingAddressID, order.TaxTotal, order.ShippingCost, order.CouponID,
                                             order.Discount, currentUser);
            }
        }