public ActionResult Edit([Bind(Include = "ccType,ccNumber,ccSecurityNumber,ccHolderName,ccExpirationMonth,ccExpirationYear,ShippingAccountID,Building,Street,City,Province,PostalCode,PhoneNumber,Email,ContactPersonName,CompanyName,DepartmentName")] BusinessShippingAccount businessShippingAccount)
        {
            if (ModelState.IsValid)
            {
                //db.Entry(businessShippingAccount).State = EntityState.Modified;
                //db.SaveChanges();

                var ent = (BusinessShippingAccount)db.ShippingAccounts.Find(businessShippingAccount.ShippingAccountID);
                ent.CompanyName       = businessShippingAccount.CompanyName;
                ent.DepartmentName    = businessShippingAccount.DepartmentName;
                ent.ContactPersonName = businessShippingAccount.ContactPersonName;
                ent.PhoneNumber       = businessShippingAccount.PhoneNumber;
                ent.Email             = businessShippingAccount.Email;
                ent.Building          = businessShippingAccount.Building;
                ent.Street            = businessShippingAccount.Street;
                ent.City              = businessShippingAccount.City;
                ent.Province          = businessShippingAccount.Province;
                ent.PostalCode        = businessShippingAccount.PostalCode;
                ent.ccType            = businessShippingAccount.ccType;
                ent.ccNumber          = businessShippingAccount.ccNumber;
                ent.ccSecurityNumber  = businessShippingAccount.ccSecurityNumber;
                ent.ccHolderName      = businessShippingAccount.ccHolderName;
                ent.ccExpirationMonth = businessShippingAccount.ccExpirationMonth;
                ent.ccExpirationYear  = businessShippingAccount.ccExpirationYear;
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }
            return(View(businessShippingAccount));
        }
        public ActionResult Edit([Bind(Include = "ShippingAccountNumber, UserName, ShippingAccountID,BuildingInformation,StreetInformation,City,ProvinceCode,PostalCode,CardType,CardNumber,SecurityNumber,CardHolderName,Month,Year,PhoneNumber,EmailAddress,ContactPersonName,CompanyName,DepartmentName")] BusinessShippingAccount businessShippingAccount)
        {
            ViewBag.Cities = db.Destinations.Select(a => a.City).Distinct().ToList();
            if (!ValidateCard(businessShippingAccount.CardNumber, businessShippingAccount.CardType))
            {
                ViewBag.errorMessage = "the card number does not match the card type";
                return(View(businessShippingAccount));
            }
            DateTime expireDate = new DateTime(int.Parse(businessShippingAccount.Year), int.Parse(businessShippingAccount.Month), 1);

            if (!isTodayOrLater(expireDate))
            {
                ViewBag.errorMessage = "expire date error";
                return(View(businessShippingAccount));
            }
            if (ModelState.IsValid)
            {
                db.Entry(businessShippingAccount).State = EntityState.Modified;
                try
                {
                    if (!CityMatchProCode(businessShippingAccount.City, businessShippingAccount.ProvinceCode))
                    {
                        return(View(businessShippingAccount));
                    }
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    return(View());
                }
                return(RedirectToAction("Index", "Home"));
            }
            return(View(businessShippingAccount));
        }
        public async Task <ActionResult> EditBusinessProfile([Bind(Include = "ShippingAccountId,AccountType,UserName,PhoneNumber,Email,Building,Street,City,Province,PostalCode,CreditCardType,CreditCardNumber,CreditCardSecurityNumber,CardholderName,CreditCardExpiryMonth,CreditCardExpiryYear,ContactPersonName,CompanyName,DepartmentName")] BusinessShippingAccount model)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());

            int?id = model.ShippingAccountId;

            user.PhoneNumber = model.PhoneNumber;
            user.Email       = model.Email;

            var result = await UserManager.UpdateAsync(user);

            if (!result.Succeeded)
            {
                AddErrors(result);
            }

            db.Entry(model).State = EntityState.Modified;
            db.SaveChanges();

            return(RedirectToAction("Index", new { Message = ManageMessageId.EditProfileSuccess }));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            BusinessShippingAccount businessShippingAccount = (BusinessShippingAccount)db.ShippingAccounts.Find(id);

            db.ShippingAccounts.Remove(businessShippingAccount);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #5
0
 public ActionResult Edit([Bind(Include = "ShippingAccountID,BuildingInformation,StreetInformation,City,ProvinceCode,PostalCode,CardType,CardNumber,SecurityNumber,CardHolderName,Month,Year,PhoneNumber,EmailAddress,ContactPersonName,CompanyName,DepartmentName")] BusinessShippingAccount businessShippingAccount)
 {
     if (ModelState.IsValid)
     {
         db.Entry(businessShippingAccount).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(businessShippingAccount));
 }
 public ActionResult Edit([Bind(Include = "ShippingAccountId,PhoneNumber,Email,Building,Street,City,Province,PostalCode,CreditCardType,CreditCardNumber,CreditCardSecurityNumber,CardholderName,CreditCardExpiryMonth,CreditCardExpiryYear,ContactPersonName,CompanyName,DepartmentName")] BusinessShippingAccount businessShippingAccount)
 {
     if (ModelState.IsValid)
     {
         db.Entry(businessShippingAccount).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index", "Home"));
     }
     return(View(businessShippingAccount));
 }
Пример #7
0
        // GET: BusinessShippingAccounts/Create

        /*public ActionResult Create()
         * {
         *  return View();
         * }*/

        // POST: BusinessShippingAccounts/Create
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for
        // more details see http://go.microsoft.com/fwlink/?LinkId=317598.

        /*[HttpPost]
         * [ValidateAntiForgeryToken]
         * public ActionResult Create([Bind(Include = "ShippingAccountId,PhoneNumber,EmailAddress,BuildingInformation,StreetInformation,City,ProvinceCode,PostalCode,Type,Number,SecurityNumber,CardholderName,ExpiryMonth,ExpiryYear,ContactPersonName,CompanyName,DepartmentName")] BusinessShippingAccount businessShippingAccount)
         * {
         *  if (ModelState.IsValid)
         *  {
         *      db.ShippingAccounts.Add(businessShippingAccount);
         *      db.SaveChanges();
         *      return RedirectToAction("Index");
         *  }
         *
         *  return View(businessShippingAccount);
         * }*/

        // GET: BusinessShippingAccounts/Edit
        public ActionResult Edit()
        {
            BusinessShippingAccount businessShippingAccount = (BusinessShippingAccount)db.ShippingAccounts.SingleOrDefault(s => s.UserName == User.Identity.Name);

            ViewBag.Cities = new SelectList(db.Destinations, "City", "City", businessShippingAccount.City);
            if (businessShippingAccount == null)
            {
                return(HttpNotFound());
            }
            return(View(businessShippingAccount));
        }
        public ActionResult Index()
        {
            var    userQuery = from s in db.ShippingAccounts select new { s.ShippingAccountID, s.UserName };
            string username  = User.Identity.GetUserName();

            userQuery = userQuery.Where(s => s.UserName == username);
            int account = userQuery.ToList()[0].ShippingAccountID;
            BusinessShippingAccount shippingAccount = (BusinessShippingAccount)db.ShippingAccounts.Find(account);

            return(View(shippingAccount));
        }
        public ActionResult Create([Bind(Include = "ShippingAccountId,BuildingInformation,StreetInformation,City,ProvinceCode,PostalCode,PhoneNumber,Email,ContactPerson,CompanyName,DepartmentName")] BusinessShippingAccount businessShippingAccount)
        {
            if (ModelState.IsValid)
            {
                //db.ShippingAccounts.Add(businessShippingAccount);
                //db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(businessShippingAccount));
        }
        public ActionResult Create([Bind(Include = "ShippingAccountId,Building,Street,City,ProvinceCode,PostalCode,Type,CardNumber,SecurityNumber,CardholderName,ExpiryMonth,ExpiryYear,PhoneNumber,EmailAddress,AccountNumber,ContactPersonName,CompanyName,DepartmentName")] BusinessShippingAccount businessShippingAccount)
        {
            if (ModelState.IsValid)
            {
                //db.ShippingAccounts.Add(businessShippingAccount);
                //db.SaveChanges();
                return(RedirectToAction("Index", "Home"));
            }

            return(View(businessShippingAccount));
        }
 public ActionResult Edit([Bind(Include = "ShippingAccountId,Building,Street,City,ProvinceCode,PostalCode,Type,CardNumber,SecurityNumber,CardholderName,ExpiryMonth,ExpiryYear,PhoneNumber,EmailAddress,AccountNumber,ContactPersonName,CompanyName,DepartmentName")] BusinessShippingAccount businessShippingAccount)
 {
     if (ModelState.IsValid)
     {
         businessShippingAccount.UserName        = User.Identity.Name; // newly added for User Profile
         db.Entry(businessShippingAccount).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("DisplayInfo", "Account"));  // newly added for User Profile
         //return RedirectToAction("Index");     //original
     }
     return(View(businessShippingAccount));
 }
        // GET: BusinessShippingAccounts/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BusinessShippingAccount businessShippingAccount = (BusinessShippingAccount)db.ShippingAccounts.Find(id);

            if (businessShippingAccount == null)
            {
                return(HttpNotFound());
            }
            return(View(businessShippingAccount));
        }
        public ActionResult EditBusinessProfile(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BusinessShippingAccount model = (BusinessShippingAccount)db.ShippingAccounts.Find(id);

            ViewBag.DisplayedShippingAccountId = ShowShippingAccountId((int)id);
            if (model == null)
            {
                return(HttpNotFound());
            }
            return(View(model));
        }
Пример #14
0
        public ActionResult GetBusinessShippingAccountRecord()
        {
            string userName = System.Web.HttpContext.Current.User.Identity.Name;

            if (userName == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BusinessShippingAccount businessShippingAccount = (BusinessShippingAccount)db.ShippingAccounts.SingleOrDefault(s => s.UserName == userName);

            if (businessShippingAccount == null)
            {
                return(HttpNotFound("There is no business shipping account with user name \"" + userName + "\""));
            }
            return(View(businessShippingAccount));
        }
Пример #15
0
        // GET: BusinessShippingAccounts/Details/5
        public ActionResult Details(int?id)
        {
            if (User.Identity.Name == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var query = db.BusinessShippingAccounts.SingleOrDefault(c => c.UserName == User.Identity.Name);

            id = query.ShippingAccountId;
            BusinessShippingAccount businessShippingAccount = (BusinessShippingAccount)db.ShippingAccounts.Find(id);

            if (businessShippingAccount == null)
            {
                return(HttpNotFound());
            }
            return(View(businessShippingAccount));
        }
        // GET: BusinessShippingAccounts/Details/5
        public ActionResult Details(int?id)
        {
            if (User.Identity.Name == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var query = db.BusinessShippingAccounts.FirstOrDefault(c => c.UserName == User.Identity.Name);

            id             = query.ShippingAccountId;
            ViewBag.Cities = db.Destinations.Select(a => a.City).Distinct().ToList();
            BusinessShippingAccount businessShippingAccount = (BusinessShippingAccount)db.ShippingAccounts.Find(id);

            if (businessShippingAccount == null)
            {
                return(HttpNotFound());
            }
            return(View(businessShippingAccount));
        }
        public ActionResult Create([Bind(Include = "ShippingAccountID,BuildingInformation,StreetInformation,City,ProvinceCode,PostalCode,CardType,CardNumber,SecurityNumber,CardHolderName,Month,Year,PhoneNumber,EmailAddress,ContactPersonName,CompanyName,DepartmentName")] BusinessShippingAccount businessShippingAccount)
        {
            if (ModelState.IsValid)
            {
                db.ShippingAccounts.Add(businessShippingAccount);
                try
                {
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    return(View());
                }
                return(RedirectToAction("Index"));
            }

            return(View(businessShippingAccount));
        }
Пример #18
0
        public ActionResult GetAccountRecord()
        {
            string userName = System.Web.HttpContext.Current.User.Identity.Name;

            if (userName == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PersonalShippingAccount account1 = db.PersonalShippingAccounts.SingleOrDefault(s => s.UserName == userName);
            BusinessShippingAccount account2 = db.BusinessShippingAccounts.SingleOrDefault(s => s.UserName == userName);

            if (account1 == null && account2 == null)
            {
                return(HttpNotFound("There is no account with user name\"" + userName + "\"."));
            }
            else if (account1 != null)
            {
                ViewBag.AccountType = "Personal";
                string text = account1.ShippingAccountId.ToString();
                while (text.Length < 12)
                {
                    text = "0" + text;
                }
                ViewBag.AccountId = text;
                return(View(account1));
            }
            else if (account2 != null)
            {
                string text = account2.ShippingAccountId.ToString();
                while (text.Length < 12)
                {
                    text = "0" + text;
                }
                ViewBag.AccountId   = text;
                ViewBag.AccountType = "Business";
                return(View(account2));
            }

            return(View());
        }
Пример #19
0
        //
        // GET: /Manage/Index
        public async Task <ActionResult> Index(ManageMessageId?message)
        {
            ViewBag.StatusMessage =
                message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed."
                : message == ManageMessageId.SetPasswordSuccess ? "Your password has been set."
                : message == ManageMessageId.SetTwoFactorSuccess ? "Your two-factor authentication provider has been set."
                : message == ManageMessageId.Error ? "An error has occurred."
                : message == ManageMessageId.AddPhoneSuccess ? "Your phone number was added."
                : message == ManageMessageId.RemovePhoneSuccess ? "Your phone number was removed."
                : "";

            var userId = User.Identity.GetUserId();
            var model  = new IndexViewModel
            {
                HasPassword       = HasPassword(),
                PhoneNumber       = await UserManager.GetPhoneNumberAsync(userId),
                TwoFactor         = await UserManager.GetTwoFactorEnabledAsync(userId),
                Logins            = await UserManager.GetLoginsAsync(userId),
                BrowserRemembered = await AuthenticationManager.TwoFactorBrowserRememberedAsync(userId)
            };

            var    userQuery = from s in db.ShippingAccounts select new { s.ShippingAccountID, s.UserName };
            string username  = User.Identity.GetUserName();

            userQuery = userQuery.Where(s => s.UserName == username);
            int account = userQuery.ToList()[0].ShippingAccountID;

            ViewBag.AccountType = "Business";
            try
            {
                BusinessShippingAccount shippingAccount = (BusinessShippingAccount)db.ShippingAccounts.Find(account);
            }
            catch
            {
                ViewBag.AccountType = "Personal";
            }

            return(View(model));
        }
Пример #20
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BusinessShippingAccount businessShippingAccount = (BusinessShippingAccount)db.ShippingAccounts.Find(id);

            if (businessShippingAccount == null || businessShippingAccount.UserName != User.Identity.Name)
            {
                return(HttpNotFound());
            }

            SelectList creditCardTypes = new SelectList(new string[] {
                "Please Select",
                "American Express",
                "Diners Club",
                "Discover",
                "MasterCard",
                "UnionPay",
                "Visa"
            });
            SelectList proviceCode = new SelectList(new List <SelectListItem> {
                new SelectListItem {
                    Value = "AH", Text = "Anhui Province", Selected = false
                },
                new SelectListItem {
                    Value = "BJ", Text = "Beijing Municipality", Selected = false
                },
                new SelectListItem {
                    Value = "CQ", Text = "Chongqing Municipality", Selected = false
                },
                new SelectListItem {
                    Value = "FJ", Text = "Fujian Province", Selected = false
                },
                new SelectListItem {
                    Value = "GD", Text = "Guangdong Province", Selected = false
                },
                new SelectListItem {
                    Value = "GS", Text = "Gansu Province", Selected = false
                },
                new SelectListItem {
                    Value = "GX", Text = "Guangxi Zhuang Autonomous Region", Selected = false
                },
                new SelectListItem {
                    Value = "GZ", Text = "Guizhou Province", Selected = false
                },
                new SelectListItem {
                    Value = "HA", Text = "Henan Province", Selected = false
                },
                new SelectListItem {
                    Value = "HB", Text = "Hubei Province", Selected = false
                },
                new SelectListItem {
                    Value = "HE", Text = "Hebei Province", Selected = false
                },
                new SelectListItem {
                    Value = "HI", Text = "Hainan Province", Selected = false
                },
                new SelectListItem {
                    Value = "HK", Text = "Hong Kong Special Administrative Region", Selected = false
                },
                new SelectListItem {
                    Value = "HL", Text = "Heilongjiang Province", Selected = false
                },
                new SelectListItem {
                    Value = "HN", Text = "Hunan Province", Selected = false
                },
                new SelectListItem {
                    Value = "JL", Text = "Jilin Province", Selected = false
                },
                new SelectListItem {
                    Value = "JS", Text = "Jiangsu Province", Selected = false
                },
                new SelectListItem {
                    Value = "JX", Text = "Jiangxi Province", Selected = false
                },
                new SelectListItem {
                    Value = "LN", Text = "Liaoning Province", Selected = false
                },
                new SelectListItem {
                    Value = "MC", Text = "Macau Special Administrative Region", Selected = false
                },
                new SelectListItem {
                    Value = "NM", Text = "Inner Mongolia Autonomous Region", Selected = false
                },
                new SelectListItem {
                    Value = "NX", Text = "Ningxia Hui Autonomous Region", Selected = false
                },
                new SelectListItem {
                    Value = "QH", Text = "Qinghai Province", Selected = false
                },
                new SelectListItem {
                    Value = "SC", Text = "Sichuan Province", Selected = false
                },
                new SelectListItem {
                    Value = "SD", Text = "Shandong Province", Selected = false
                },
                new SelectListItem {
                    Value = "SH", Text = "Shanghai Municipality", Selected = false
                },
                new SelectListItem {
                    Value = "SN", Text = "Shaanxi Province", Selected = false
                },
                new SelectListItem {
                    Value = "SX", Text = "Shanxi Province", Selected = false
                },
                new SelectListItem {
                    Value = "TJ", Text = "Tianjin Municipality", Selected = false
                },
                new SelectListItem {
                    Value = "TW", Text = "Taiwan Province", Selected = false
                },
                new SelectListItem {
                    Value = "XJ", Text = "Xinjiang Uyghur Autonomous Region", Selected = false
                },
                new SelectListItem {
                    Value = "XZ", Text = "Tibet Autonomous Region", Selected = false
                },
                new SelectListItem {
                    Value = "YN", Text = "Yunnan Province", Selected = false
                },
                new SelectListItem {
                    Value = "ZJ", Text = "Zhejiang Province", Selected = false
                }
            }, "Value", "Text");

            ViewBag.CreditCardTypes  = creditCardTypes;
            ViewBag.ProvinceCodeList = proviceCode;

            return(View(businessShippingAccount));
        }
Пример #21
0
        public ActionResult GeneratePaymentHistoryReport(
            int?ShippingAccountId,
            int?WaybillId,
            DateTime?StartingDate,
            DateTime?EndingDate,
            string sortOrder,
            int?currentShippingAccountId,
            int?currentWaybillId,
            DateTime?currentStartingDate,
            DateTime?currentEndingDate,
            int?page)
        {
            // Instantiate an instance of the PaymentsReportViewModel and the PaymentsSearchViewModel.
            var PaymentReport = new PaymentsReportViewModel();

            PaymentReport.PaymentSearch = new PaymentsSearchViewModel();

            // Code for paging.
            ViewBag.CurrentSort = sortOrder;
            int pageSize   = 5;
            int pageNumber = (page ?? 1);

            // Retain search conditions for sorting.
            if (StartingDate == null)
            {
                StartingDate = currentStartingDate;
            }
            if (EndingDate == null)
            {
                EndingDate = currentEndingDate;
            }
            if (ShippingAccountId == null)
            {
                ShippingAccountId = currentShippingAccountId;
            }
            if (WaybillId == null)
            {
                WaybillId = currentWaybillId;
            }
            else
            {
                page = 1;
            }
            ViewBag.CurrentShippingAccountId = ShippingAccountId;
            ViewBag.CurrentWaybillId         = WaybillId;
            ViewBag.CurrentStartingDate      = StartingDate;
            ViewBag.CurrentEndingDate        = EndingDate;

            PaymentReport.PaymentSearch.ShippingAccountId = ShippingAccountId == null ? 0 : (int)ShippingAccountId;
            PaymentReport.PaymentSearch.WaybillId         = WaybillId == null ? 0 : (int)WaybillId;
            // Populate the ShippingAccountId dropdown list.

            if (User.IsInRole("Employee"))
            {
                var n = PopulateShippingAccountsDropdownList().ToList();
                foreach (SelectListItem k in n)
                {
                    k.Value = k.Text;
                }
                n.Insert(0, new SelectListItem
                {
                    Text  = "All",
                    Value = "0"
                });
                int haha = 0;
                for (int i = 0; i < n.Count(); i++)
                {
                    if (n.ElementAt(i).Value == ShippingAccountId.ToString())
                    {
                        haha = i;
                        break;
                    }
                }
                foreach (var item in n)
                {
                    if (item.Value == ShippingAccountId.ToString())
                    {
                        item.Selected = true;
                    }
                }
                PaymentReport.PaymentSearch.ShippingAccounts = n;
                if (!(ShippingAccountId == 0 || ShippingAccountId == null))
                {
                    string accountusername = db.ShippingAccounts.Single(i => i.ShippingAccountId == ShippingAccountId).UserName;
                    PaymentReport.PaymentSearch.WaybillIds = new SelectList(db.Payments.Where(o => o.UserName == accountusername).Select(o => o.WaybillID).Distinct()).ToList();
                }
                else
                {
                    IQueryable <int> foo = Enumerable.Empty <int>().AsQueryable();
                    foo = foo.Concat(new int[] { 0 });
                    PaymentReport.PaymentSearch.WaybillIds = new SelectList(foo).ToList();
                }
            }
            else
            {
                PaymentReport.PaymentSearch.ShippingAccounts = null;
                string accountusername = GetCurrentAccount().UserName;
                PaymentReport.PaymentSearch.WaybillIds = new SelectList(db.Payments.Where(o => o.UserName == accountusername).Select(o => o.WaybillID).Distinct()).ToList();
            }

            //Initialize the query to retrieve payments using the PaymentsListViewModel.
            var list = new List <PaymentsListViewModel>();

            foreach (Payment v in db.Payments)
            {
                PaymentsListViewModel m = new PaymentsListViewModel();
                Shipment ship           = db.Shipments.SingleOrDefault(a => a.WaybillId == v.WaybillID);
                m.WaybillId          = v.WaybillID;
                m.ShippingAccountId  = v.PayerCharacter == "Recipient" ? ship.RecipientShippingAccountID : ship.SenderShippingAccountID;
                m.ShipDate           = (DateTime)ship.PickupDate;
                m.RecipientName      = ship.RecipientFullName;
                m.OriginCity         = ship.Origin;
                m.DestinationCity    = ship.Destination;
                m.ServiceType        = db.ServiceTypes.Single(a => a.ServiceTypeID == ship.ServiceTypeID).Type;
                m.TotalPaymentAmount = v.PaymentAmount;
                m.PaymentDescription = v.PaymentDescription;
                m.CurrencyCode       = v.CurrencyCode;

                ShippingAccount lala_account  = db.ShippingAccounts.Single(a => a.UserName == v.UserName);
                Shipment        lala_shipment = db.Shipments.Single(a => a.WaybillId == v.WaybillID);
                m.SenderReferenceNumber = lala_shipment.ReferenceNumber;
                m.SenderFullName        = "";
                if (lala_shipment.SenderShippingAccount is PersonalShippingAccount)
                {
                    PersonalShippingAccount temp = (PersonalShippingAccount)db.ShippingAccounts.Single(a => a.ShippingAccountId == lala_shipment.SenderShippingAccountID);
                    m.SenderFullName = temp.FirstName + temp.LastName;
                }
                else
                {
                    BusinessShippingAccount temp = (BusinessShippingAccount)db.ShippingAccounts.Single(a => a.ShippingAccountId == lala_shipment.SenderShippingAccountID);
                    m.SenderFullName = temp.ContactPersonName;
                }
                m.SenderMailingAddress     = lala_shipment.SenderShippingAccount.ProvinceCode + ", " + lala_shipment.SenderShippingAccount.City + ", " + lala_shipment.SenderShippingAccount.StreetInformation + ", " + lala_shipment.SenderShippingAccount.BuildingInformation;
                m.RecipientFullName        = lala_shipment.RecipientFullName;
                m.RecipientDeliveryAddress = lala_shipment.RecipientDeliveryProvince + ", " + lala_shipment.RecipientDeliveryCity + ", " + lala_shipment.RecipientDeliveryStreet + ", " + lala_shipment.RecipientDeliveryBuilding;
                m.CreditCardType           = lala_account.Type;
                m.CreditCardNumber         = lala_account.Number.Substring(lala_account.Number.Length - 4);
                m.AuthorizationCode        = v.AuthorizationCode;

                m.Packages = lala_shipment.Packages;
                list.Add(m);
            }
            var paymentQuery = list.AsQueryable();

            // Add the condition to select a spefic shipping account if shipping account id is not null.

            if (User.IsInRole("Employee"))
            {
                if (ShippingAccountId != 0 && ShippingAccountId != null)
                {
                    paymentQuery = paymentQuery.Where(s => s.ShippingAccountId == ShippingAccountId);
                    if (WaybillId != 0 && WaybillId != null)
                    {
                        paymentQuery = paymentQuery.Where(s => s.WaybillId == WaybillId);
                    }
                }
            }
            else
            {
                int accountid = GetCurrentAccount().ShippingAccountId;
                ViewBag.lala = accountid;
                paymentQuery = paymentQuery.Where(p => p.ShippingAccountId == accountid);
                if (WaybillId != 0 && WaybillId != null)
                {
                    paymentQuery = paymentQuery.Where(s => s.WaybillId == WaybillId);
                }
            }


            if ((StartingDate != null) && (EndingDate != null))
            {
                paymentQuery = paymentQuery.Where(s => (s.ShipDate > StartingDate && s.ShipDate < EndingDate));
            }
            else
            {
                // Return an empty result if no shipping account id has been selected.
                PaymentReport.PaymentList = new PaymentsListViewModel[0].ToPagedList(pageNumber, pageSize);
            }

            // Code for sorting on ServiceType, ShippedDate, DeliveredDate, RecipientName, Origin, Destination
            ViewBag.ServiceTypeSortParm   = sortOrder == "serviceType" ? "serviceType_desc" : "serviceType";
            ViewBag.ShippedDateSortParm   = sortOrder == "shippedDate" ? "shippedDate_desc" : "shippedDate";
            ViewBag.RecipientNameSortParm = sortOrder == "recipientName" ? "recipientName_desc" : "recipientName";
            ViewBag.OriginSortParm        = sortOrder == "origin" ? "origin_desc" : "origin";
            ViewBag.DestinationSortParm   = sortOrder == "destination" ? "destination_desc" : "destination";
            ViewBag.InvoiceAmountSortParm = sortOrder == "invoiceAmount" ? "invoiceAmount_desc" : "invoiceAmount";
            switch (sortOrder)
            {
            case "serviceType_desc":
                paymentQuery = paymentQuery.OrderByDescending(s => s.ServiceType);
                break;

            case "serviceType":
                paymentQuery = paymentQuery.OrderBy(s => s.ServiceType);
                break;

            case "shippedDate_desc":
                paymentQuery = paymentQuery.OrderByDescending(s => s.ShipDate);
                break;

            case "shippedDate":
                paymentQuery = paymentQuery.OrderBy(s => s.ShipDate);
                break;

            case "recipientName_desc":
                paymentQuery = paymentQuery.OrderByDescending(s => s.RecipientName);
                break;

            case "recipientName":
                paymentQuery = paymentQuery.OrderBy(s => s.RecipientName);
                break;

            case "origin_desc":
                paymentQuery = paymentQuery.OrderByDescending(s => s.OriginCity);
                break;

            case "origin":
                paymentQuery = paymentQuery.OrderBy(s => s.OriginCity);
                break;

            case "destination_desc":
                paymentQuery = paymentQuery.OrderByDescending(s => s.DestinationCity);
                break;

            case "destination":
                paymentQuery = paymentQuery.OrderBy(s => s.DestinationCity);
                break;

            case "invoiceAmount_desc":
                paymentQuery = paymentQuery.OrderByDescending(s => s.TotalPaymentAmount);
                break;

            case "invoiceAmount":
                paymentQuery = paymentQuery.OrderBy(s => s.TotalPaymentAmount);
                break;

            default:
                paymentQuery = paymentQuery.OrderBy(s => s.WaybillId);
                break;
            }
            PaymentReport.PaymentList = paymentQuery.ToPagedList(pageNumber, pageSize);
            if (ShippingAccountId != null && ShippingAccountId != 0 && WaybillId != 0 && WaybillId != null)
            {
                ViewBag.ShowShipmentPackages = true;
            }
            else
            {
                ViewBag.ShowShipmentPackages = null;
            }
            return(View(PaymentReport));
        }
Пример #22
0
 public void ComposeInvoice(Shipment shipment)
 {
     if (shipment.RecipientPaysShipment == shipment.RecipientPaysTaxesDuties)
     {
         Invoice invoice = new Invoice();
         invoice.WaybillId = shipment.WaybillId;
         if (db.TrackingSystemRecords.Count() == 0)
         {
             invoice.ShipDate = DateTime.Now;
         }
         else
         {
             invoice.ShipDate = db.TrackingSystemRecords.Where(s => s.WaybillId == shipment.WaybillId).OrderBy(S => S.DateTimeOfRecord).First().DateTimeOfRecord;
         }
         ShippingAccount rec;
         if (shipment.RecipientPaysShipment)
         {
             rec = db.ShippingAccounts.Find(shipment.RecipientId);
         }
         else
         {
             rec = shipment.Sender;
         }
         invoice.ShippingAccountId = rec.ShippingAccountId;
         try
         {
             BusinessShippingAccount BSA = (BusinessShippingAccount)rec;
             invoice.RecipientName = BSA.ContactPersonName;
         }
         catch (Exception)
         {
             PersonalShippingAccount PSA = (PersonalShippingAccount)rec;
             invoice.RecipientName = PSA.FirstName + " " + PSA.LastName;
         }
         invoice.Origin        = shipment.Origin;
         invoice.Destination   = shipment.Destination;
         invoice.ServiceType   = shipment.ServiceType;
         invoice.InvoiceAmount = shipment.ShipmentFee + shipment.TotalTaxes + shipment.TotalDuties;
         db.Invoices.Add(invoice);
         db.SaveChanges();
     }
     else
     {
         Invoice invoice  = new Invoice();
         Invoice invoice2 = new Invoice();
         invoice.WaybillId  = shipment.WaybillId;
         invoice.ShipDate   = db.TrackingSystemRecords.Where(s => s.WaybillId == shipment.WaybillId).OrderBy(S => S.DateTimeOfRecord).First().DateTimeOfRecord;
         invoice2.WaybillId = shipment.WaybillId;
         invoice2.ShipDate  = db.TrackingSystemRecords.Where(s => s.WaybillId == shipment.WaybillId).OrderBy(S => S.DateTimeOfRecord).First().DateTimeOfRecord;
         ShippingAccount sen, rec;
         sen = shipment.Sender;
         rec = db.ShippingAccounts.Find(shipment.RecipientId);
         try
         {
             BusinessShippingAccount BSA = (BusinessShippingAccount)sen;
             invoice.RecipientName = BSA.ContactPersonName;
         }
         catch (Exception)
         {
             PersonalShippingAccount PSA = (PersonalShippingAccount)sen;
             invoice.RecipientName = PSA.FirstName + " " + PSA.LastName;
         }
         try
         {
             BusinessShippingAccount BSA = (BusinessShippingAccount)rec;
             invoice2.RecipientName = BSA.ContactPersonName;
         }
         catch (Exception)
         {
             PersonalShippingAccount PSA = (PersonalShippingAccount)rec;
             invoice2.RecipientName = PSA.FirstName + " " + PSA.LastName;
         }
         invoice.Origin       = shipment.Origin;
         invoice.Destination  = shipment.Destination;
         invoice.ServiceType  = shipment.ServiceType;
         invoice2.Origin      = shipment.Origin;
         invoice2.Destination = shipment.Destination;
         invoice2.ServiceType = shipment.ServiceType;
         if (shipment.RecipientPaysShipment)
         {
             invoice.InvoiceAmount  = shipment.ShipmentFee;
             invoice2.InvoiceAmount = shipment.TotalTaxes + shipment.TotalDuties;
         }
         else
         {
             invoice2.InvoiceAmount = shipment.ShipmentFee;
             invoice.InvoiceAmount  = shipment.TotalTaxes + shipment.TotalDuties;
         }
         db.Invoices.Add(invoice);
         db.Invoices.Add(invoice2);
         db.SaveChanges();
     }
 }
Пример #23
0
        public async Task <ActionResult> Create([Bind(Include = "TrackingID,WaybillId,Time,Description,Location,Remark,DeliveredTo,DeliveredAt,StatusInformation")] Tracking tracking)
        {
            Shipment shipment = db.Shipments.Single(s => s.WaybillId == tracking.WaybillId && s.CancelledOrNot == false);

            tracking.Shipment = shipment;
            if (a)
            {
                ViewBag.AlreadyEnterWaybillId = true;
                ViewBag.WaybillId             = tracking.WaybillId;
            }
            else
            {
                ViewBag.WaybillId             = new SelectList(db.Shipments.Where(s => s.CancelledOrNot == false && s.PickupOrNot == true && s.DeliveredOrNot == false), "WaybillId", "WaybillId", tracking.WaybillId);
                ViewBag.AlreadyEnterWaybillId = false;
            }

            if (tracking.Description == "Delivered" || tracking.Description == "Returned" || tracking.Description == "Lost")
            {
                shipment.DeliveredOrNot = true;
                shipment.DeliveredDate  = tracking.Time;
                db.SaveChanges();
            }
            if (ModelState.IsValid)
            {
                db.Trackings.Add(tracking);
                db.SaveChanges();

                shipment.Trackings.Add(tracking);
                db.Entry(shipment).State = EntityState.Modified;
                db.SaveChanges();

                //delivered notification email
                if (tracking.Description == "Delivered" && shipment.NotifySenderOrNot)
                {
                    var    body_delivered    = "<p>Dear user {0}: </p><p>The shipment with the following details has been delivered to the destination.</p><p>Shipment waybill Id: {1}</p><p>Delivered remark: {2}</p><p>Recipient name: {3}</p><p>Recipient address: {4}</p><p>Delivered date: {5}</p>";
                    var    message_delivered = new MailMessage();
                    string Username          = shipment.SenderShippingAccount.UserName;
                    string WaybillId         = shipment.WaybillId.ToString("000000000000");
                    string Notification      = tracking.Remark;
                    string RecipientName     = "";
                    if (shipment.RecipientShippingAccount is PersonalShippingAccount)
                    {
                        PersonalShippingAccount b = (PersonalShippingAccount)db.ShippingAccounts.Single(a => a.ShippingAccountId == shipment.RecipientShippingAccountID);
                        RecipientName = b.FirstName + b.LastName;
                    }
                    else
                    {
                        BusinessShippingAccount b = (BusinessShippingAccount)db.ShippingAccounts.Single(a => a.ShippingAccountId == shipment.RecipientShippingAccountID);
                        RecipientName = b.ContactPersonName;
                    }
                    string RecipientAddress = shipment.RecipientShippingAccount.ProvinceCode + ", " + shipment.RecipientShippingAccount.City + ", " + shipment.RecipientShippingAccount.StreetInformation + ", " + shipment.RecipientShippingAccount.BuildingInformation;
                    string DeliveredDate    = ((DateTime)(tracking.Time)).ToString("yyyy/MM/dd HH:mm");
                    message_delivered.To.Add(new MailAddress(shipment.SenderShippingAccount.EmailAddress));
                    message_delivered.Subject    = "Delivered Notification Email";
                    message_delivered.Body       = String.Format(body_delivered, Username, WaybillId, Notification, RecipientName, RecipientAddress, DeliveredDate);
                    message_delivered.IsBodyHtml = true;
                    using (var smtp = new SmtpClient())
                    {
                        await smtp.SendMailAsync(message_delivered);
                    }
                }
                return(RedirectToAction("Index"));
            }

            return(View(tracking));
        }
Пример #24
0
        public ActionResult Create([Bind(Include = "TrackingID,WaybillNumber,DateTime,Description,Location,Remarks, Type, DeliveredTo, DeliveredAt")] Tracking tracking, string submit)
        {
            if (submit == "select waybill")
            {
                Shipment shipment = db.Shipments.FirstOrDefault(a => a.WaybillNumber == tracking.WaybillNumber);
                if (shipment == null)
                {
                    return(Create());
                }

                string status = shipment.Status;
                if (status == "pending" || status == "delivered" || status == "lost" || status == "cancelled" || status == "returned")
                {
                    ViewBag.msg  = "This shipment is not avaliable for tracking";
                    ViewBag.page = 1;
                    return(View());
                }
                else if (status == "confirmed")
                {
                    ViewBag.Types    = new string[1];
                    ViewBag.Types[0] = "picked_up";
                    ViewBag.page     = 2;
                    return(View(tracking));
                }
                else if (status == "picked_up" || status == "invoice_sent")
                {
                    ViewBag.Types    = new string[4];
                    ViewBag.Types[0] = "delivered";
                    ViewBag.Types[1] = "lost";
                    ViewBag.Types[2] = "returned";
                    ViewBag.Types[3] = "other";
                    ViewBag.page     = 2;
                    return(View(tracking));
                }
            }
            else if (submit == "select type")
            {
                if (tracking.Type == "delivered")
                {
                    ViewBag.page = 3;
                }
                else
                {
                    ViewBag.page = 4;
                }
                return(View(tracking));
            }
            else if (submit == "save")
            {
                if (ModelState.IsValid)
                {
                    string WaybillNumber = tracking.WaybillNumber;
                    tracking.WaybillId = db.Shipments.FirstOrDefault(a => a.WaybillNumber == WaybillNumber).WaybillId;
                    if (tracking.Type == "delivered" || tracking.Type == "lost" || tracking.Type == "picked_up" || tracking.Type == "returned")
                    {
                        Shipment shipment = db.Shipments.FirstOrDefault(a => a.WaybillNumber == WaybillNumber);
                        shipment.Status = tracking.Type;

                        if (tracking.Type == "picked_up")
                        {
                            shipment.ShippedDate = tracking.DateTime;
                        }
                        if (tracking.Type == "delivered")
                        {
                            shipment.DeliveredDate = tracking.DateTime;
                        }

                        // if send picked up notification to recipient
                        if (shipment.IfSendEmailRecipient == true && tracking.Type == "picked_up")
                        {
                            MailMessage mailMessage = new MailMessage();
                            //Add recipients
                            mailMessage.To.Add(shipment.Recipient.EmailAddress);
                            //mailMessage.To.Add(shipment.ShippingAccount.EmailAddress);
                            //Setting the displayed email address and display name
                            //!!!Do not use this to prank others!!!
                            mailMessage.From = new MailAddress("*****@*****.**", "SinEx Notification");
                            var senderName = "";
                            if (shipment.ShippingAccount is PersonalShippingAccount)
                            {
                                PersonalShippingAccount person = (PersonalShippingAccount)shipment.ShippingAccount;
                                senderName = person.FirstName + " " + person.LastName;
                            }
                            else if (shipment.ShippingAccount is BusinessShippingAccount)
                            {
                                BusinessShippingAccount business = (BusinessShippingAccount)shipment.ShippingAccount;
                                senderName = business.ContactPersonName + ", " + business.CompanyName;
                            }
                            string senderAddr = shipment.ShippingAccount.BuildingInformation + ", "
                                                + shipment.ShippingAccount.StreetInformation + ", "
                                                + shipment.ShippingAccount.City + ", "
                                                + shipment.ShippingAccount.ProvinceCode + ", "
                                                + shipment.ShippingAccount.PostalCode;
                            //Subject and content of the email
                            mailMessage.Subject = "Pick up notification for Your Shipment (Waybill No. " + shipment.WaybillNumber + ")";
                            mailMessage.Body    = "Dear Customer,\n \nYour shipment with waybillnumber " + shipment.WaybillNumber +
                                                  " has been picked up. \n\nDetailed information are as follows: \n"
                                                  + "Sender name:\t" + senderName
                                                  + "\nSender address:\t" + senderAddr
                                                  + "\nPick up date:\t" + tracking.DateTime;
                            mailMessage.Priority = MailPriority.Normal;

                            //Instantiate a new SmtpClient instance
                            SmtpClient smtpClient = new SmtpClient("smtp.cse.ust.hk");

                            //WARNING: DO NOT set any credentials and other settings!!!

                            //Send
                            try
                            {
                                smtpClient.Send(mailMessage);
                            }
                            catch (Exception e)
                            {
                                ViewBag.msg = e;
                                return(View());
                            }
                        }

                        // if send delivered notification to sender
                        if (shipment.IfSendEmail == true && tracking.Type == "delivered")
                        {
                            MailMessage mailMessage = new MailMessage();
                            //Add recipients
                            mailMessage.To.Add(shipment.ShippingAccount.EmailAddress);
                            //mailMessage.To.Add(shipment.Recipient.EmailAddress);
                            //Setting the displayed email address and display name
                            //!!!Do not use this to prank others!!!
                            mailMessage.From = new MailAddress("*****@*****.**", "SinEx Notification");
                            var    RecipientName = shipment.Recipient.FullName;
                            string RecipientAddr = shipment.Recipient.Building
                                                   + ", " + shipment.Recipient.Street
                                                   + ", " + shipment.Recipient.City
                                                   + ", " + shipment.Recipient.ProvinceCode;
                            //Subject and content of the email
                            mailMessage.Subject = "Delivery notification for Your Shipment (Waybill No. " + shipment.WaybillNumber + ")";
                            mailMessage.Body    = "Dear Customer, \n \nYour shipment with waybillnumber " + shipment.WaybillNumber +
                                                  " has been delivered. \n\nDetailed information are as follows: \n"
                                                  + "Recipient name:\t" + RecipientName
                                                  + "\nRecipient address:\t" + RecipientAddr
                                                  + "\nDelivered date:\t" + tracking.DateTime;
                            mailMessage.Priority = MailPriority.Normal;

                            //Instantiate a new SmtpClient instance
                            SmtpClient smtpClient = new SmtpClient("smtp.cse.ust.hk");

                            //WARNING: DO NOT set any credentials and other settings!!!

                            //Send
                            try
                            {
                                smtpClient.Send(mailMessage);
                            }
                            catch (Exception e)
                            {
                                ViewBag.msg = e;
                                return(View());
                            }
                        }
                    }
                    db.Trackings.Add(tracking);
                    try
                    {
                        db.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        ViewBag.msg = e;
                        return(View());
                    }
                    return(RedirectToAction("Index", "Home"));
                }
            }

            // ViewBag.WaybillId = new SelectList(db.Shipments, "WaybillId", "ReferenceNumber", tracking.WaybillId);
            return(View(tracking));
        }