Пример #1
0
        public ActionResult GetTime(DateTime Time, int WaybillId)
        {
            if (string.IsNullOrEmpty(Time.ToString()))
            {
                return(Json(null, JsonRequestBehavior.AllowGet));
            }
            ShippingAccount current_account = GetCurrentAccount();
            var             hehe            = db.Trackings.Where(a => a.WaybillId == WaybillId).Select(a => a.Time).OrderBy(a => a);
            bool            faultornot      = false;
            DateTime        haha            = new DateTime();

            foreach (DateTime hihi in hehe)
            {
                if (Time <= hihi)
                {
                    faultornot = true;
                    haha       = hihi;
                    break;
                }
            }
            if (faultornot)
            {
                return(Json(haha, JsonRequestBehavior.AllowGet));
            }

            return(Json(null, JsonRequestBehavior.AllowGet));
        }
Пример #2
0
        public ActionResult Index(
            int WaybillId
            )
        {
            ViewBag.Waybillid = WaybillId;
            Shipment shipment = db.Shipments.Single(s => s.WaybillId == WaybillId);

            if (shipment == null)
            {
                return(HttpNotFound());
            }
            else
            {
                ViewBag.CancelledOrNot = shipment.CancelledOrNot;
                ViewBag.ConfirmOrNot   = shipment.ConfirmOrNot;
            }
            if (User.IsInRole("Customer"))
            {
                ShippingAccount shippingAccount = db.ShippingAccounts.SingleOrDefault(s => s.UserName == User.Identity.Name);
                //check if the waybill belongs to the current user
                if (shipment.SenderShippingAccountID != shippingAccount.ShippingAccountId)
                {
                    return(HttpNotFound());
                }
            }
            //get packages from database
            var packages = db.Packages.Include(p => p.Currency).Include(p => p.PackageType).Include(p => p.Shipment).Where(p => p.WaybillId == shipment.WaybillId);

            return(View(packages.ToList()));
        }
Пример #3
0
        //
        // GET: /Manage/Index
        public async Task <ActionResult> Index(ManageMessageId?message)
        {
            if (User.IsInRole("Customer"))
            {
                SinExDatabaseContext DB = new SinExDatabaseContext();

                string user_name = System.Web.HttpContext.Current.User.Identity.Name;

                if (user_name == null)
                {
                    return(RedirectToAction("ManageLogins", new { Message = message }));
                }

                ShippingAccount current_user = DB.ShippingAccounts.SingleOrDefault(c => c.UserName == user_name);

                if (current_user is BusinessShippingAccount)
                {
                    ViewBag.customerType = "Business";
                }
                else if (current_user is PersonalShippingAccount)
                {
                    ViewBag.customerType = "Personal";
                }
            }

            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();

            string account_number = "";

            if (User.IsInRole("Customer"))
            {
                account_number = DataBase.ShippingAccounts.SingleOrDefault(n => n.UserName == User.Identity.Name).AccountNumber;
            }
            else
            {
                account_number = "";
            }
            var model = new IndexViewModel
            {
                AccountNum        = account_number,
                HasPassword       = HasPassword(),
                PhoneNumber       = await UserManager.GetPhoneNumberAsync(userId),
                TwoFactor         = await UserManager.GetTwoFactorEnabledAsync(userId),
                Logins            = await UserManager.GetLoginsAsync(userId),
                BrowserRemembered = await AuthenticationManager.TwoFactorBrowserRememberedAsync(userId)
            };

            return(View(model));
        }
Пример #4
0
        public ActionResult Create([Bind(Include = "RecipientID,FullName,CompanyName,DepartmentName,DeliveryBuilding,DeliveryStreet,DeliveryCity,DeliveryProvince,DeliveryPostcode,PhoneNumber,Email,Nickname")] Recipient recipient)
        {
            if (ModelState.IsValid)
            {
                ShippingAccount account = GetCurrentAccount();
                recipient.ShippingAccount   = account;
                recipient.ShippingAccountId = account.ShippingAccountId;


                //check duplicate or not
                bool general_duplicate        = false;
                bool nickname_duplicate       = false;
                IEnumerable <Recipient> exist = db.Recipients.Select(s => s).Where(s => s.ShippingAccountId == account.ShippingAccountId);

                foreach (var s in exist)
                {
                    if (s.FullName == recipient.FullName &&
                        s.CompanyName == recipient.CompanyName &&
                        s.DepartmentName == recipient.DepartmentName &&
                        s.DeliveryBuilding == recipient.DeliveryBuilding &&
                        s.DeliveryStreet == recipient.DeliveryStreet &&
                        s.DeliveryCity == recipient.DeliveryCity &&
                        s.DeliveryProvince == recipient.DeliveryProvince &&
                        s.DeliveryPostcode == recipient.DeliveryPostcode &&
                        s.Email == recipient.Email &&
                        s.PhoneNumber == recipient.PhoneNumber &&
                        s.DeliveryStreet == recipient.DeliveryStreet &&
                        s.DeliveryCity == recipient.DeliveryCity)
                    {
                        general_duplicate = true;
                        break;
                    }
                }

                foreach (var s in exist)
                {
                    if (s.Nickname == recipient.Nickname)
                    {
                        nickname_duplicate = true;
                        break;
                    }
                }
                ViewBag.general_duplicate  = general_duplicate;
                ViewBag.nickname_duplicate = nickname_duplicate;

                if (!general_duplicate && !nickname_duplicate)
                {
                    db.Recipients.Add(recipient);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(View("CreateFail"));
                }
            }
            return(View(recipient));
        }
Пример #5
0
        public ActionResult Index()
        {
            var pickupLocations = db.PickupLocations.Include(p => p.ShippingAccount);

            if (User.IsInRole("Customer"))
            {
                ShippingAccount shippingAccount = GetCurrentAccount();
                pickupLocations = pickupLocations.Where(s => s.ShippingAccountId == shippingAccount.ShippingAccountId);
            }
            return(View(pickupLocations.ToList()));
        }
Пример #6
0
        public ActionResult Index()
        {
            var recipients = db.Recipients.Include(p => p.ShippingAccount);

            if (User.IsInRole("Customer"))
            {
                ShippingAccount shippingAccount = GetCurrentAccount();
                recipients = recipients.Where(s => s.ShippingAccountId == shippingAccount.ShippingAccountId);
            }
            return(View(recipients.ToList()));
        }
Пример #7
0
        private ShippingAccount GetCurrentAccount()
        {
            string username = System.Web.HttpContext.Current.User.Identity.Name;

            if (username == null)
            {
                return(null);
            }
            ShippingAccount current_account = db.ShippingAccounts.SingleOrDefault(s => s.UserName == username);

            return(current_account);
        }
Пример #8
0
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Recipient       recipient      = db.Recipients.Find(id);
            ShippingAccount currentAccount = GetCurrentAccount();

            if (recipient == null || recipient.ShippingAccountId != currentAccount.ShippingAccountId)
            {
                return(HttpNotFound());
            }
            return(View(recipient));
        }
Пример #9
0
        public ActionResult Edit([Bind(Include = "RecipientID,FullName,CompanyName,DepartmentName,DeliveryBuilding,DeliveryStreet,DeliveryCity,DeliveryProvince,DeliveryPostcode,PhoneNumber,Email,Nickname")] Recipient recipient)
        {
            if (ModelState.IsValid)
            {
                ShippingAccount account = GetCurrentAccount();
                recipient.ShippingAccount   = account;
                recipient.ShippingAccountId = account.ShippingAccountId;

                db.Entry(recipient).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.ShippingAccountId = new SelectList(db.ShippingAccounts, "ShippingAccountId", "UserName", recipient.ShippingAccountId);
            return(View(recipient));
        }
Пример #10
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Recipient       recipient      = db.Recipients.Find(id);
            ShippingAccount currentAccount = GetCurrentAccount();

            if (recipient == null || recipient.ShippingAccountId != currentAccount.ShippingAccountId)
            {
                return(HttpNotFound());
            }
            ViewBag.ShippingAccountId = new SelectList(db.ShippingAccounts, "ShippingAccountId", "UserName", recipient.ShippingAccountId);
            return(View(recipient));
        }
Пример #11
0
        public ActionResult GetLocation(string Location)
        {
            if (string.IsNullOrEmpty(Location))
            {
                return(Json(null, JsonRequestBehavior.AllowGet));
            }

            ShippingAccount current_account = GetCurrentAccount();
            var             hehe            = db.PickupLocations.Where(a => a.ShippingAccountId == current_account.ShippingAccountId).Select(a => a.Location);

            if (hehe.Contains(Location))
            {
                return(Json(current_account.UserName, JsonRequestBehavior.AllowGet));
            }

            return(Json(null, JsonRequestBehavior.AllowGet));
        }
Пример #12
0
        public ActionResult GetRecipientNickname(string Nickname)
        {
            if (string.IsNullOrEmpty(Nickname))
            {
                return(Json(null, JsonRequestBehavior.AllowGet));
            }

            ShippingAccount current_account = GetCurrentAccount();
            var             hehe            = db.Recipients.Where(a => a.ShippingAccountId == current_account.ShippingAccountId).Select(a => a.Nickname);

            if (hehe.Contains(Nickname))
            {
                return(Json(current_account.UserName, JsonRequestBehavior.AllowGet));
            }

            return(Json(null, JsonRequestBehavior.AllowGet));
        }
Пример #13
0
        public ActionResult Create([Bind(Include = "PickupLocationID,ShippingAccountId,Nickname,Location")] PickupLocation pickupLocation)
        {
            if (ModelState.IsValid)
            {
                ShippingAccount account = GetCurrentAccount();
                pickupLocation.ShippingAccount   = account;
                pickupLocation.ShippingAccountId = account.ShippingAccountId;

                //check duplicate or not
                bool general_duplicate             = false;
                bool nickname_duplicate            = false;
                IEnumerable <PickupLocation> exist = db.PickupLocations.Select(s => s).Where(s => s.ShippingAccountId == account.ShippingAccountId);

                foreach (var s in exist)
                {
                    if (s.Location == pickupLocation.Location)
                    {
                        general_duplicate = true;
                        break;
                    }
                }

                foreach (var s in exist)
                {
                    if (s.Nickname == pickupLocation.Nickname)
                    {
                        nickname_duplicate = true;
                        break;
                    }
                }
                ViewBag.general_duplicate  = general_duplicate;
                ViewBag.nickname_duplicate = nickname_duplicate;
                if (!general_duplicate && !nickname_duplicate)
                {
                    db.PickupLocations.Add(pickupLocation);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(View("CreateFail"));
                }
            }
            return(View(pickupLocation));
        }
Пример #14
0
        public ActionResult GetGeneralRecipient(
            string FullName,
            string CompanyName,
            string DepartmentName,
            string DeliveryBuilding,
            string DeliveryStreet,
            string DeliveryCity,
            string DeliveryProvince,
            string DeliveryPostcode,
            string PhoneNumber,
            string Email)
        {
            if (string.IsNullOrEmpty(FullName) ||
                string.IsNullOrEmpty(CompanyName) ||
                string.IsNullOrEmpty(DepartmentName) ||
                string.IsNullOrEmpty(DeliveryBuilding) ||
                string.IsNullOrEmpty(DeliveryStreet) ||
                string.IsNullOrEmpty(DeliveryCity) ||
                string.IsNullOrEmpty(DeliveryProvince) ||
                string.IsNullOrEmpty(DeliveryPostcode) ||
                string.IsNullOrEmpty(PhoneNumber) ||
                string.IsNullOrEmpty(Email))
            {
                return(Json(null, JsonRequestBehavior.AllowGet));
            }
            ShippingAccount current_account = GetCurrentAccount();
            var             hehe            = db.Recipients.Where(a => a.ShippingAccountId == current_account.ShippingAccountId &&
                                                                  a.FullName == FullName &&
                                                                  a.CompanyName == CompanyName &&
                                                                  a.DepartmentName == DepartmentName &&
                                                                  a.DeliveryBuilding == DeliveryBuilding &&
                                                                  a.DeliveryStreet == DeliveryStreet &&
                                                                  a.DeliveryCity == DeliveryCity &&
                                                                  a.DeliveryProvince == DeliveryProvince &&
                                                                  a.DeliveryPostcode == DeliveryPostcode &&
                                                                  a.PhoneNumber == PhoneNumber &&
                                                                  a.Email == Email).Select(a => a.ShippingAccountId);

            if (hehe.Contains(current_account.ShippingAccountId))
            {
                return(Json(current_account.UserName, JsonRequestBehavior.AllowGet));
            }
            return(Json(null, JsonRequestBehavior.AllowGet));
        }
Пример #15
0
        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)
            };

            if (User.IsInRole("Customer"))
            {
                ShippingAccount CShippingAccount = db.ShippingAccounts.SingleOrDefault(s => s.UserName == User.Identity.Name);
                if (CShippingAccount is BusinessShippingAccount)
                {
                    ViewBag.AccountType = "BusinessShippingAccount";
                }
                else if (CShippingAccount is PersonalShippingAccount)
                {
                    ViewBag.AccountType = "PersonalShippingAccount";
                }
                //assign a 12-digit account number
                ViewBag.AccountNumber = CShippingAccount.ShippingAccountId.ToString("000000000000");
            }



            return(View(model));
        }
Пример #16
0
        // GET: Packages
        public ActionResult Index(int WaybillID)
        {
            ViewBag.WaybillID = WaybillID;
            Shipment shipment = db.Shipments.Single(s => s.WaybillID == WaybillID);

            if (shipment == null)
            {
                return(HttpNotFound());
            }
            if (Request.IsAuthenticated)
            {
                ShippingAccount shippingAccount = db.ShippingAccounts.SingleOrDefault(s => s.UserName == User.Identity.Name);
                //check if the waybill belongs to the current user
                if (shipment.ShippingAccountID != shippingAccount.ShippingAccountID)
                {
                    return(HttpNotFound());
                }
            }

            var packages = db.Packages.Include(p => p.Currency).Include(p => p.PackageType).Include(p => p.Shipment).Where(p => p.WaybillID == shipment.WaybillID);

            return(View(packages.ToList()));
        }
        public ActionResult Edit()
        {
            var UserName = System.Web.HttpContext.Current.User.Identity.Name;

            if (UserName == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ShippingAccount Account = db.ShippingAccounts.SingleOrDefault(a => a.UserName == UserName);

            if (Account == null)
            {
                return(HttpNotFound("Account not found with this username:"******"../PersonalShippingAccounts/Edit", (PersonalShippingAccount)Account));
            }
            else
            {
                return(View("../BusinessShippingAccounts/Edit", (BusinessShippingAccount)Account));
            }
        }
Пример #18
0
        public async Task <ActionResult> Register(RegisterCustomerViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (model.PersonalInformation != null)
                {
                    model.LoginInformation.Email = model.PersonalInformation.EmailAddress;
                    if (!ValidateCard(model.PersonalInformation.CardNumber, model.PersonalInformation.CardType))
                    {
                        return(RedirectToAction("Register", "Account", new { accountType = "Personal", error = 1 }));
                    }
                    DateTime expireDate = new DateTime(int.Parse(model.PersonalInformation.Year), int.Parse(model.PersonalInformation.Month), 1);
                    if (!isTodayOrLater(expireDate))
                    {
                        return(RedirectToAction("Register", "Account", new { accountType = "Personal", error = 3 }));
                    }
                }
                else // AccountType = "Business"
                {
                    model.LoginInformation.Email = model.BusinessInformation.EmailAddress;
                    if (!ValidateCard(model.BusinessInformation.CardNumber, model.BusinessInformation.CardType))
                    {
                        return(RedirectToAction("Register", "Account", new { accountType = "Business", error = 1 }));
                    }
                    DateTime expireDate = new DateTime(int.Parse(model.BusinessInformation.Year), int.Parse(model.BusinessInformation.Month), 1);
                    if (!isTodayOrLater(expireDate))
                    {
                        return(RedirectToAction("Register", "Account", new { accountType = "Business", error = 3 }));
                    }
                }
                var user = new ApplicationUser {
                    UserName = model.LoginInformation.UserName, Email = model.LoginInformation.Email
                };
                var result = await UserManager.CreateAsync(user, model.LoginInformation.Password);

                if (result.Succeeded)
                {
                    // Assign user to Customer role.
                    var roleResult = await UserManager.AddToRolesAsync(user.Id, "Customer");

                    if (roleResult.Succeeded)
                    {
                        // Create a shipping account for the customer.
                        int             id           = db.ShippingAccounts.Count() + 1;
                        string          strID        = id.ToString().PadLeft(12, '0');
                        ShippingAccount shippingacct = null;
                        if (model.PersonalInformation != null)
                        {
                            model.PersonalInformation.UserName = user.UserName;
                            model.PersonalInformation.ShippingAccountNumber = strID;
                            model.PersonalInformation.ShippingAccountId     = id;
                            db.ShippingAccounts.Add(model.PersonalInformation);
                            shippingacct = model.PersonalInformation;
                        }
                        else
                        {
                            model.BusinessInformation.UserName = user.UserName;
                            model.BusinessInformation.ShippingAccountNumber = strID;
                            model.BusinessInformation.ShippingAccountId     = id;
                            db.ShippingAccounts.Add(model.BusinessInformation);
                            shippingacct = model.BusinessInformation;
                        }
                        try
                        {
                            if (ValidCity(shippingacct.City))
                            {
                                string ProvinceCode = db.Destinations.SingleOrDefault(a => a.City == shippingacct.City).ProvinceCode;
                                if (ProvinceCode != shippingacct.ProvinceCode)
                                {
                                    ViewBag.errorMessage = "City and Province must match";
                                    // return View(model);
                                    if (shippingacct is PersonalShippingAccount)
                                    {
                                        return(RedirectToAction("register", "account", new { accounttype = "personal", error = 2 }));
                                    }
                                    else
                                    {
                                        return(RedirectToAction("register", "account", new { accounttype = "business", error = 2 }));
                                    }
                                }
                            }
                            else
                            {
                                ViewBag.errorMessage = "Please input a valid city";
                                if (shippingacct is PersonalShippingAccount)
                                {
                                    return(RedirectToAction("Register", "Account", new { accountType = "Personal" }));
                                }
                                else
                                {
                                    return(RedirectToAction("Register", "Account", new { accountType = "Business" }));
                                }
                                // return View(model);
                            }
                            db.SaveChanges();
                            // send confirmation email
                            MailMessage mailMessage = new MailMessage();
                            //Add recipients
                            ShippingAccount account = null;
                            if (model.PersonalInformation != null)
                            {
                                // personal shipping account
                                account = model.PersonalInformation;
                            }
                            else
                            {
                                // business shipping account
                                account = model.BusinessInformation;
                            }
                            mailMessage.To.Add(account.EmailAddress);

                            //Setting the displayed email address and display name
                            //!!!Do not use this to prank others!!!
                            mailMessage.From = new MailAddress("*****@*****.**", "SinEx Confirmation");
                            var name = account.UserName;
                            //Subject and content of the email
                            mailMessage.Subject = "Account Confirmation";
                            mailMessage.Body    = "Dear " + name + ",\n \n your account with account number " + account.ShippingAccountNumber +
                                                  " has been created.\n Thank you for choosing SinEx \n\n Best regards,\nSino Express";
                            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.errorMessage = e;
                                //return View();
                            }
                        }
                        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);
                                }
                            }
                            throw;
                        }
                        await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                        // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                        // Send an email with this link
                        // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                        // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                        // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                        return(RedirectToAction("Index", "Home"));
                    }
                    else
                    {
                        AddErrors(roleResult);
                    }
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            if (model.PersonalInformation != null)
            {
                return(RedirectToAction("Register", "Account", new { accountType = "Personal" }));
            }
            else // AccountType = "Business"
            {
                return(RedirectToAction("Register", "Account", new { accountType = "Business" }));
            }
        }
Пример #19
0
        public ActionResult ConfirmingShipment(int?id, bool?IsImmediatePickup, DateTime PickupTime)
        {
            if (id == null || IsImmediatePickup == null || PickupTime == null)
            {
                return(RedirectToAction("ConfirmShipment"));
            }
            List <string> errorList = new List <string>();

            if (!(bool)IsImmediatePickup)
            {
                if (PickupTime < DateTime.Now)
                {
                    errorList.Add("Pickup can only be arranged in the future.");
                }
                else if (PickupTime.Subtract(DateTime.Now).Days > 4)
                {
                    errorList.Add("Pickup can only be arranged within 5 days.");
                }
            }
            Shipment shipment = db.Shipments.Find(id);

            if (shipment.NumberOfPackages == 0)
            {
                errorList.Add("You don't have any package in this shipment.");
            }
            else if (shipment.NumberOfPackages > 10)
            {
                errorList.Add("You can have at most 10 packages.");
            }
            if (shipment.RecipientPaysShipment || shipment.RecipientPaysTaxesDuties)
            {
                ShippingAccount Recipient = db.ShippingAccounts.Find(shipment.RecipientId);
                if (Recipient == null)
                {
                    errorList.Add("No valid recipient shipping account found.");
                }
            }
            if (errorList.Count == 0)
            {
                shipment.Status            = "Confirmed";
                shipment.isConfirmed       = true;
                shipment.IsImmediatePickup = (bool)IsImmediatePickup;
                shipment.PickupTime        = PickupTime;

                db.Entry(shipment).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            else
            {
                Session["HandlingWaybillId"]  = id;
                ViewBag.DeliveryAddressEntity = GetAddressEntity(shipment.DeliveryAddress);
                ViewBag.PickupAddressEntity   = GetAddressEntity(shipment.PickupAddress);
                if (isPersonalShippingAccount(shipment.SenderId))
                {
                    ViewBag.SenderName = ((PersonalShippingAccount)shipment.Sender).FirstName + " " + ((PersonalShippingAccount)shipment.Sender).LastName;
                }
                else
                {
                    ViewBag.SenderName = ((BusinessShippingAccount)shipment.Sender).ContactPersonName;
                }
                ViewBag.confirmErrorList = errorList;
                return(View(shipment));
            }
        }
Пример #20
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));
        }