Exemple #1
0
        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);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(businessShippingAccount));
        }
        public ActionResult Create([Bind(Include = "PackageTypeID,Type,Description")] PackageType packageType)
        {
            if (ModelState.IsValid)
            {
                db.PackageTypes.Add(packageType);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(packageType));
        }
        public ActionResult Create([Bind(Include = "ServiceTypeID,Type,CutoffTime,DeliveryTime")] ServiceType serviceType)
        {
            if (ModelState.IsValid)
            {
                db.ServiceTypes.Add(serviceType);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(serviceType));
        }
Exemple #4
0
        public ActionResult Create([Bind(Include = "CurrencyCode,ExchangeRate")] Currency currency)
        {
            if (ModelState.IsValid)
            {
                db.Currencies.Add(currency);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(currency));
        }
Exemple #5
0
        public ActionResult Create([Bind(Include = "WaybillId,ReferenceNumber,ServiceType,ShippedDate,DeliveredDate,RecipientName,NumberOfPackages,Origin,Destination,Status,ShippingAccountId")] Shipment shipment)
        {
            if (ModelState.IsValid)
            {
                db.Shipments.Add(shipment);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(shipment));
        }
        public ActionResult Create([Bind(Include = "DestinationID,City,ProvinceCode")] Destination destination)
        {
            if (ModelState.IsValid)
            {
                db.Destinations.Add(destination);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(destination));
        }
        public ActionResult Create([Bind(Include = "PakageTypeSizeID,size,weightLimit,PackageTypeID")] PakageTypeSize pakageTypeSize)
        {
            if (ModelState.IsValid)
            {
                db.PakageTypeSizes.Add(pakageTypeSize);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.PackageTypeID = new SelectList(db.PackageTypes, "PackageTypeID", "Type", pakageTypeSize.PackageTypeID);
            return(View(pakageTypeSize));
        }
        public ActionResult Create([Bind(Include = "ServicePackageFeeID,Fee,MinimumFee,PackageTypeID,ServiceTypeID")] ServicePackageFee servicePackageFee)
        {
            if (ModelState.IsValid)
            {
                db.ServicePackageFees.Add(servicePackageFee);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.PackageTypeID = new SelectList(db.PackageTypes, "PackageTypeID", "Type", servicePackageFee.PackageTypeID);
            ViewBag.ServiceTypeID = new SelectList(db.ServiceTypes, "ServiceTypeID", "Type", servicePackageFee.ServiceTypeID);
            return(View(servicePackageFee));
        }
        public ActionResult Edit(PersonalShippingAccount personalShippingAccount)
        {
            ViewBag.Cities = db.Destinations.Select(a => a.City).Distinct().ToList();
            if (!ValidateCard(personalShippingAccount.CardNumber, personalShippingAccount.CardType))
            {
                ViewBag.errorMessage = "the card number does not match the card type";
                return(View(personalShippingAccount));
            }
            DateTime expireDate = new DateTime(int.Parse(personalShippingAccount.Year), int.Parse(personalShippingAccount.Month), 1);

            if (!isTodayOrLater(expireDate))
            {
                ViewBag.errorMessage = "expire date error";
                return(View(personalShippingAccount));
            }
            if (ModelState.IsValid)
            {
                db.Entry(personalShippingAccount).State = EntityState.Modified;
                try
                {
                    if (!CityMatchProCode(personalShippingAccount.City, personalShippingAccount.ProvinceCode))
                    {
                        return(View(personalShippingAccount));
                    }
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    return(View());
                }
                return(RedirectToAction("Index", "Home"));
            }
            return(View(personalShippingAccount));
        }
Exemple #10
0
        //  [ValidateAntiForgeryToken]
        public ActionResult Create(string submit, NewPickupViewModel pickupView)   //model binding
        {
            DateTime endDate = DateTime.Now.AddDays(5);

            if (pickupView.Pickup.Date > endDate || pickupView.Pickup.Date < DateTime.Today)
            {
                return(RedirectToAction("Create", "Pickups", new { waybillId = pickupView.WaybillId, validDate = "false" }));
            }


            /* Add saved address functionality */
            var shipment = (from s in db.Shipments
                            where s.WaybillId == pickupView.WaybillId
                            select s).First();
            var shippingAccount = (from s in db.ShippingAccounts
                                   where s.UserName == User.Identity.Name
                                   select s).First();

            shipment.Pickup.Date = pickupView.Pickup.Date;

            if (pickupView.PickupLocationNickname != null)
            {
                shipment.Pickup.Location = pickupView.PickupLocationNickname;
            }
            else
            {
                shipment.Pickup.Location = pickupView.Pickup.Location;
            }

            shipment.Pickup.Type = pickupView.Pickup.Type;

            /* need to add pickup */
            //  db.Pickups.Add(pickupView.Pickup);
            try
            {
                shipment.Status = "confirmed";
                db.SaveChanges();
            }
            catch (DbEntityValidationException e)
            {
                Console.WriteLine(e);
            }
            return(RedirectToAction("Index", "Shipments"));
        }
        public ActionResult Create([Bind(Include = "CurrencyCode,ExchangeRate")] Currency currency)
        {
            if (ModelState.IsValid)
            {
                db.Currencies.Add(currency);
                try
                {
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    return(View());
                }
                return(RedirectToAction("Index"));
            }

            return(View(currency));
        }
Exemple #12
0
        public ActionResult Create([Bind(Include = "PenaltyFeeID,Fee")] PenaltyFee penaltyFee)
        {
            if (ModelState.IsValid)
            {
                db.PenaltyFees.Add(penaltyFee);
                try
                {
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    return(View());
                }
                return(RedirectToAction("Index"));
            }

            return(View(penaltyFee));
        }
        public ActionResult Create([Bind(Include = "DestinationID,City,ProvinceCode")] Destination destination)
        {
            if (ModelState.IsValid)
            {
                db.Destinations.Add(destination);
                try
                {
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    return(View());
                }
                return(RedirectToAction("Index"));
            }

            return(View(destination));
        }
 public ActionResult Edit([Bind(Include = "ShippingAccountID,BuildingInformation,StreetInformation,City,ProvinceCode,PostalCode,CardType,CardNumber,SecurityNumber,CardHolderName,Month,Year,PhoneNumber,EmailAddress,FirstName,LastName")] PersonalShippingAccount personalShippingAccount)
 {
     if (ModelState.IsValid)
     {
         db.Entry(personalShippingAccount).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index", "Home"));
     }
     return(View(personalShippingAccount));
 }
        public ActionResult Create([Bind(Include = "ServiceTypeID,Type,CutoffTime,DeliveryTime")] ServiceType serviceType)
        {
            if (ModelState.IsValid)
            {
                db.ServiceTypes.Add(serviceType);
                try
                {
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    return(View());
                }
                return(RedirectToAction("Index"));
            }

            return(View(serviceType));
        }
        public ActionResult Create([Bind(Include = "PackageTypeID,Type,Description")] PackageType packageType)
        {
            if (ModelState.IsValid)
            {
                db.PackageTypes.Add(packageType);
                try
                {
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    return(View());
                }
                return(RedirectToAction("Index"));
            }

            return(View(packageType));
        }
        public ActionResult Create([Bind(Include = "RecipientID,FullName,CompanyName,DepartmentName,DeliveryAddress,PhoneNumber,EmailAddress")] Recipient recipient)
        {
            if (ModelState.IsValid)
            {
                db.Recipients.Add(recipient);
                try
                {
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    return(View());
                }
                return(RedirectToAction("Index"));
            }

            return(View(recipient));
        }
        public ActionResult Create([Bind(Include = "InvoiceID,AuthenticationCode,Type,ShippingAccountNumber,TotalAmountPayable,WaybillId")] Invoice invoice)
        {
            if (ModelState.IsValid)
            {
                db.Invoices.Add(invoice);
                try
                {
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    return(View());
                }
                return(RedirectToAction("Index"));
            }

            ViewBag.WaybillId = new SelectList(db.Shipments, "WaybillId", "ReferenceNumber", invoice.WaybillId);
            return(View(invoice));
        }
Exemple #19
0
        public ActionResult Create(string type_post, SavedAddressViewModel savedAddressViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(savedAddressViewModel));
            }
            SavedAddress savedAddress = new SavedAddress();

            savedAddress = savedAddressViewModel.SavedAddress;

            /*Empty entry exception */
            if (savedAddressViewModel.SavedAddress.NickName == null)
            {
                ViewBag.errorMessage = "You are required to assign a nickname to the location";
                return(View(savedAddressViewModel));
            }



            ViewBag.ShippingAccountId = new SelectList(db.ShippingAccounts, "ShippingAccountId", "ShippingAccountNumber", savedAddress.ShippingAccountId);
            var shippingAccount = (from s in db.ShippingAccounts
                                   where s.UserName == User.Identity.Name
                                   select s).First();
            bool isExist = (from s in db.SavedAddresses
                            where s.ShippingAccountId == shippingAccount.ShippingAccountId &&
                            s.NickName == savedAddress.NickName
                            select s).Any();

            if (isExist)
            {
                ViewBag.errorMessage = "The nickname already exists! Please choose another one";
                return(View(savedAddressViewModel));
            }

            /*Empty entry exception */
            if (savedAddressViewModel.SavedAddress.PickupLocation == null && savedAddressViewModel.SavedAddress.Type == "pickup")
            {
                ViewBag.errorMessage2 = "Please enter a pickup location";
                return(View(savedAddressViewModel));
            }

            savedAddress.ShippingAccountId = shippingAccount.ShippingAccountId;
            db.SavedAddresses.Add(savedAddress);

            try
            {
                db.SaveChanges();
            }
            catch (DbEntityValidationException e)
            {
                Console.WriteLine(e);
            }


            if (type_post == "CreateAndReturnToPickup")
            {
                return(RedirectToAction("Create", "Pickups", new { waybillId = savedAddressViewModel.WaybillId }));
            }

            return(RedirectToAction("Index"));
        }
        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));
        }