Exemplo n.º 1
0
            public void the_customer_should_be_persisted()
            {
                //Arrange
                var mockCustomerRepository    = new Mock <ICustomerRepository>();
                var mockMailingAddressFactory = new Mock <IMailingAddressFactory>();

                var mailingAddress = new MailingAddress {
                    Country = "Canada"
                };

                mockMailingAddressFactory
                .Setup(x => x.TryParse(It.IsAny <string>(), out mailingAddress))
                .Returns(true);

                var customerService = new CustomerService(
                    mockCustomerRepository.Object,
                    mockMailingAddressFactory.Object
                    );

                //Act
                customerService.Create(new CustomerToCreateDto());

                //Assert
                mockCustomerRepository.Verify(x => x.Save(It.IsAny <Customer>()));
            }
Exemplo n.º 2
0
        public override object CreateBulkRegistrationType(Taxpayer taxpayer)
        {
            var items = RegistrationIndicatorItems.Select(x => x.MapStateRegistrationIndicator());

            var physicalAddress = PhysicalAddress?.MapAddressType();
            var mailingAddress  = MailingAddress?.MapAddressType();
            var contactInfo     = ContactInfo?.MapContactInformation();
            var technologyModel = TechnologyModel?.MapTechnologyModel();

            var record = new BulkRegistrationNewType
            {
                ActionCode         = BulkRegistrationNewTypeActionCode.N,
                RegistrationEntity = EnumHelper.GetEnumItemFromValueName <EntityType>(EntityType),
                NAICSCode          = NaicsCode,
                PhysicalAddress    = physicalAddress,
                MailingAddress     = mailingAddress ?? physicalAddress,
                SSTPContact        = contactInfo,
                TechnologyModel    = technologyModel,
                Item                       = taxpayer.MapTaxpayerName(),
                SellerPhone                = taxpayer.SellerPhone,
                SellerPhoneExt             = taxpayer.SellerPhoneExtension,
                StateIncorporated          = taxpayer.StateIncorporated,
                EffectiveDate              = DateTime.UtcNow,
                FirstFilingPeriod          = $"{DateTime.UtcNow.Year}-{DateTime.UtcNow:MM}",
                NewPass                    = taxpayer.Password,
                StateRegistrationIndicator = items.ToArray(),
                DBAName                    = taxpayer.DoingBusinessName
            };

            return(record);
        }
Exemplo n.º 3
0
        public void Create_ValidCommand_Client_Should_Be_Persisted()
        {
            //Arrange
            var createCommmand = new CustomerCreateCommand()
            {
                FirstName = "Mohamed",
                LastName  = "Ahmed"
            };

            MailingAddress mailingAddress = new MailingAddress()
            {
                Street = "Test Street", StreetNumber = 10
            };

            var mockRepository            = new Mock <ICustomerRepository>();
            var mockMailingAddressFactory = new Mock <IMailingAddressFactory>();

            mockRepository.Setup(x => x.Save(It.IsAny <Customer>()));

            mockMailingAddressFactory.Setup(x => x.TryParse(It.IsAny <string>(), out mailingAddress))
            .Returns(true);

            CustomerService_4 customerService = new CustomerService_4(mockMailingAddressFactory.Object, mockRepository.Object);

            //Act
            customerService.Create(createCommmand);

            //Assert
            mockRepository.Verify(x => x.Save(It.IsAny <Customer>()));
        }
Exemplo n.º 4
0
        public ActionResult Add(AddressViewModel model)
        {
            MessageBase result = new MessageBase();

            if (model.UserId > 0)
            {
                var v = new MailingAddress()
                {
                    UserId   = model.UserId.ToString(),
                    Province = model.Province,
                    City     = model.City,
                    County   = model.County,
                    Address  = model.Address,
                    Name     = model.Name,
                    Phone    = model.Phone,
                    ZipCode  = model.ZipCode,
                    AddTime  = DateTime.Now,
                    Status   = 1
                };

                _mailingAddressService.Add(v);
                result.Status = Constant.SUCCESS;
            }
            else
            {
                result.Status = Constant.FAILED;
            }

            return(Json(result));
        }
        public void Update(MailingAddress item)
        {
            using (APCRSHREntities context = new APCRSHREntities())
            {
                var mailing = context.MailingAddresses.Where(a => a.MailingAddressID.Equals(item.MailingAddressID)).SingleOrDefault();
                if (mailing != null)
                {
                    mailing.UserID               = item.UserID;
                    mailing.UpdatedDate          = DateTime.Now;
                    mailing.ParticipantType      = item.ParticipantType;
                    mailing.ParticipateYouth     = item.ParticipateYouth;
                    mailing.OriginalNationality  = item.OriginalNationality;
                    mailing.CurrentNationality   = item.CurrentNationality;
                    mailing.PassportNumber       = item.PassportNumber;
                    mailing.TypeOfPassport       = item.TypeOfPassport;
                    mailing.Occupation           = item.Occupation;
                    mailing.DateOfPassportIssue  = item.DateOfPassportIssue;
                    mailing.DateOfPassportExpiry = item.DateOfPassportExpiry;
                    mailing.PassportPhoto1       = item.PassportPhoto1;
                    mailing.PassportPhoto2       = item.PassportPhoto2;
                    mailing.PassportPhoto3       = item.PassportPhoto3;
                    mailing.DetailOfEmbassy      = item.DetailOfEmbassy;
                    mailing.NeedVisaSupport      = item.NeedVisaSupport;
                    mailing.ActivationCode       = item.ActivationCode;
                    mailing.RegistrationNumber   = item.RegistrationNumber;

                    context.SaveChanges();
                }
                else
                {
                    throw new Exception(string.Format("Mailing id {0} invalid", item.MailingAddressID));
                }
            }
        }
Exemplo n.º 6
0
            public void the_customer_should_be_persisted()
            {
                /**Arrange**/

                var mockCustomerRepository    = new Mock <ICustomerRepository>();
                var mockMailingAddressFactory = new Mock <IMailingAddressFactory>();

                //What we're doing here is defining the MailingAddress object that will be returned by the out parameter
                //of the MailingAddressFactory
                var mailingAddress = new MailingAddress {
                    Country = "Canada"
                };

                //Now setup the mockMailingAddressFactory so that when it's TryParse method is called and It is passed Any Type of String,
                //that it will return the mailingAddress object that was created above.
                mockMailingAddressFactory
                .Setup(x => x.TryParse(It.IsAny <string>(), out mailingAddress))
                .Returns(true);     //The value returned from the TryParse method is to be true (note that we don't use this value in CustomerService
                                    //and instead use 'if (mailingAddress == null)', but we could!

                var customerService = new CustomerService(
                    mockCustomerRepository.Object, mockMailingAddressFactory.Object);

                /**Act**/

                customerService.Create(new CustomerToCreateDto());

                /**Assert**/

                mockCustomerRepository.Verify(x => x.Save(It.IsAny <Customer>()));
            }
Exemplo n.º 7
0
        public void MailingAddress_CityTestInvalid(string city)
        {
            MailingAddress address = new MailingAddress();

            if (city == null)
            {
                address = new MailingAddress()
                {
                    Line1      = "1645 rue des rigoles",
                    PostalCode = "J1M2H2",
                    Province   = Enums.Province.QC
                };
            }
            else
            {
                address = new MailingAddress()
                {
                    Line1      = "1645 rue des rigoles",
                    City       = city,
                    PostalCode = "J1M2H2",
                    Province   = Enums.Province.QC
                };
            }


            var validationContext = new ValidationContext(address, serviceProvider: null, items: null);
            var validationResults = new List <ValidationResult>();
            var isValid           = Validator.TryValidateObject(address, validationContext, validationResults, true);

            Assert.False(isValid);
        }
Exemplo n.º 8
0
        public void MailingAddress_Line1TestInvalid(String line1)
        {
            MailingAddress address = new MailingAddress();

            if (line1 == null)
            {
                address = new MailingAddress()
                {
                    City       = "Sherbrooke",
                    PostalCode = "J1M2H2",
                    Province   = Enums.Province.QC
                };
            }
            else
            {
                address = new MailingAddress()
                {
                    Line1      = line1,
                    City       = "Sherbrooke",
                    PostalCode = "J1M2H2",
                    Province   = Enums.Province.QC
                };
            }


            var validationContext = new ValidationContext(address, serviceProvider: null, items: null);
            var validationResults = new List <ValidationResult>();
            var isValid           = Validator.TryValidateObject(address, validationContext, validationResults, true);

            Assert.False(isValid);
        }
Exemplo n.º 9
0
        public void MailingAddress_Line2TestValid(string line2)
        {
            MailingAddress address;

            if (line2 == null)
            {
                address = new MailingAddress()
                {
                    Line1      = "1645 rue des rigoles",
                    City       = "Sherbrooke",
                    PostalCode = "J1M2H2",
                    Province   = Enums.Province.QC
                };
            }
            else
            {
                address = new MailingAddress()
                {
                    Line1      = "1645 rue des rigoles",
                    Line2      = line2,
                    City       = "Sherbrooke",
                    PostalCode = "J1M2H2",
                    Province   = Enums.Province.QC
                };
            }


            var validationContext = new ValidationContext(address, serviceProvider: null, items: null);
            var validationResults = new List <ValidationResult>();
            var isValid           = Validator.TryValidateObject(address, validationContext, validationResults, true);

            Assert.True(isValid);
        }
        public void Create_ValidCommand_Client_Should_Be_Persisted()
        {
            //Arrange
            var createCommmand = new CustomerCreateCommand()
            {
                FirstName = "Mohamed",
                LastName = "Ahmed"
            };

            MailingAddress mailingAddress = new MailingAddress() { Street = "Test Street", StreetNumber = 10 };

            var mockRepository = new Mock<ICustomerRepository>();
            var mockMailingAddressFactory = new Mock<IMailingAddressFactory>();

            mockRepository.Setup(x => x.Save(It.IsAny<Customer>()));

            mockMailingAddressFactory.Setup(x => x.TryParse(It.IsAny<string>(), out mailingAddress))
                .Returns(true);

            CustomerService_4 customerService = new CustomerService_4(mockMailingAddressFactory.Object, mockRepository.Object);
            //Act
            customerService.Create(createCommmand);

            //Assert
            mockRepository.Verify(x => x.Save(It.IsAny<Customer>()));
        }
Exemplo n.º 11
0
        private void UpdateMailingAddress(Enrollee dbEnrollee, MailingAddress newAddress)
        {
            if (dbEnrollee.MailingAddress != null)
            {
                _context.Addresses.Remove(dbEnrollee.MailingAddress);
            }

            dbEnrollee.MailingAddress = newAddress;
        }
Exemplo n.º 12
0
        public IActionResult DeleteAddress(int MailingAddressId)
        {
            ViewData["Message"] = "Delete Address.";
            MailingAddress ma = db_context.MailingAddress.Where(o => o.MailingAddressId == MailingAddressId).FirstOrDefault();

            db_context.MailingAddress.Remove(ma);
            db_context.SaveChanges();
            return(RedirectToAction("Purchase"));
        }
 public object Insert(MailingAddress item)
 {
     using (APCRSHREntities context = new APCRSHREntities())
     {
         context.MailingAddresses.Add(item);
         context.SaveChanges();
         return(item.MailingAddressID);
     }
 }
Exemplo n.º 14
0
 bool IEquatable <AccountMailingAddressUpdated> .Equals(AccountMailingAddressUpdated other)
 {
     if (other == null)
     {
         return(false);
     }
     return(AccountId == other.AccountId &&
            ((MailingAddress != null && other.MailingAddress != null && MailingAddress.Equals(other.MailingAddress)) ||
             (MailingAddress == null && other.MailingAddress == null)));
 }
Exemplo n.º 15
0
 public Client()
 {
     ClientType        = new ClientType();
     Orders            = new List <Order>();
     MailingAddress    = new MailingAddress();
     PostOffice        = new PostOffice();
     District          = new District();
     Upazilla          = new Upazilla();
     Division          = new Division();
     Branch            = new Branch();
     ClientAttachments = new List <ClientAttachment>();
 }
        private void btnGo_Click(object sender, EventArgs e)
        {
            MailingAddress mailToMe = new MailingAddress();

            mailToMe.aptNumber = this.txtAptNumber.Text;
            mailToMe.streetAddress = this.txtStreetAddress.Text;
            mailToMe.city = this.txtCity.Text;
            mailToMe.province = this.txtProvince.Text;
            mailToMe.postalCode = this.txtPostalCode.Text;

            AddressInfo(mailToMe.streetAddress, mailToMe.city, mailToMe.province, mailToMe.postalCode, mailToMe.aptNumber);
        }
Exemplo n.º 17
0
        public ViewModel()
        {
            contacts        = new ObservableCollection <Contact>();
            selectedContact = new Contact();
            emails          = new ObservableCollection <EmailAddress>();
            selectedEmail   = new EmailAddress();
            mails           = new ObservableCollection <MailingAddress>();
            selectedMail    = new MailingAddress();
            phones          = new ObservableCollection <PhoneNumber>();
            selectedPhone   = new PhoneNumber();

            this.PropertyChanged += PropertyChangedExecute;
        }
Exemplo n.º 18
0
        private void btnGo_Click(object sender, EventArgs e)
        {
            //input
            MailingAddress mailToMe = new MailingAddress();

            mailToMe.aptNumber     = this.txtAptNumber.Text;
            mailToMe.streetAddress = this.txtStreetAddress.Text;
            mailToMe.city          = this.txtCity.Text;
            mailToMe.province      = selectedProvince;
            mailToMe.postalCode    = this.txtPostalCode.Text;

            //process
            AddressInfo(mailToMe.streetAddress, mailToMe.city, mailToMe.province, mailToMe.postalCode, mailToMe.aptNumber);
        }
        public IActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(RedirectToAction("Addresses", "Customer"));
            }
            var mailingAddress = _context.MailingAddresses
                                 .Where(i => i.CustomerId == _userManager.GetUserId(HttpContext.User));
            MailingAddress model = mailingAddress
                                   .Where(i => i.Id == id)
                                   .FirstOrDefault();

            return(View(model));
        }
 public object MapActionItem()
 {
     return(new BulkRegistrationCOUTypeBusinessInfo
     {
         DBAName = DoingBusinessName,
         NAICSCode = NaicsCode,
         PhysicalAddress = PhysicalAddress?.MapAddressType(),
         MailingAddress = MailingAddress?.MapAddressType(),
         SellerPhone = SellerPhone?.Trim(),
         SellerPhoneExt = SellerPhoneExtension,
         StateIncorporated = StateIncorporated,
         SSTPContact = ContactInfo?.MapContactInformation()
     });
 }
Exemplo n.º 21
0
        public void MailingAddress_ProvinceTestInvalid()
        {
            MailingAddress address = new MailingAddress()
            {
                Line1      = "1645 rue des rigoles",
                City       = "Sherbrooke",
                PostalCode = "J1M2H2",
            };

            var validationContext = new ValidationContext(address, serviceProvider: null, items: null);
            var validationResults = new List <ValidationResult>();
            var isValid           = Validator.TryValidateObject(address, validationContext, validationResults, true);

            Assert.False(isValid);
        }
        // PUBLIC METHODS ///////////////////////////////////////////////////
        #region Assert Methods
        public static void Equal(MailingAddress expected, MailingAddress actual)
        {
            // Handle when 'expected' is null.
            if (expected == null)
            {
                Assert.Null(actual);
                return;
            }
            Assert.NotNull(actual);

            Assert.Equal(expected.Address, actual.Address);
            Assert.Equal(expected.City, actual.City);
            Assert.Equal(expected.State, actual.State);
            Assert.Equal(expected.ZipCode, actual.ZipCode);
        }
        public IActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(RedirectToAction("Addresses", "Customer"));
            }

            var mailingAddresses = _context.MailingAddresses
                                   .Where(i => i.CustomerId == _userManager.GetUserId(HttpContext.User));
            MailingAddress target = mailingAddresses.
                                    Where(i => i.Id == id)
                                    .FirstOrDefault();

            _context.MailingAddresses.Remove(target);
            _context.SaveChanges();
            return(RedirectToAction("Addresses", "Customer"));
        }
        public IActionResult Edit(MailingAddress model)
        {
            if (ModelState.IsValid)
            {
                var mailingAddresses = _context.MailingAddresses
                                       .Where(i => i.CustomerId == _userManager.GetUserId(HttpContext.User));
                MailingAddress preUpdate = mailingAddresses
                                           .Where(i => i.Id == model.Id)
                                           .FirstOrDefault();
                _context.MailingAddresses.Remove(preUpdate);
                _context.SaveChanges();
                _context.MailingAddresses.Add(model);
                _context.SaveChanges();
                return(RedirectToAction("Addresses", "Customer"));
            }

            return(View(model));
        }
Exemplo n.º 25
0
 private void ControlsToData()
 {
     if (HasAnyAddressData)
     {
         if (_mailingAddress == null)
         {
             _mailingAddress = new MailingAddress();
         }
         var country = cbMailingCountry.SelectedItem as LuCountryBean;
         var state   = cbMailingState.SelectedItem as LuStateBean;
         _mailingAddress.Address1   = edtMailingAddress1.GetValue <string>();
         _mailingAddress.Address2   = edtMailingAddress2.GetValue <string>();
         _mailingAddress.City       = edtMailingCity.GetValue <string>();
         _mailingAddress.PostalCode = edtMailingPostalCode.GetValue <string>();
         _mailingAddress.Country    = (country == null ? null : country.countryName);
         _mailingAddress.State      = (state == null ? null : state.stateCode);
     }
     else
     {
         _mailingAddress = null;
     }
 }
Exemplo n.º 26
0
        private void UpdateMailingAddress(Enrollee dbEnrollee, MailingAddress newAddress)
        {
            if (dbEnrollee.MailingAddress != null)
            {
                _context.Addresses.Remove(dbEnrollee.MailingAddress);
            }

            if (newAddress != null)
            {
                var address = new MailingAddress
                {
                    CountryCode  = newAddress.CountryCode,
                    ProvinceCode = newAddress.ProvinceCode,
                    Street       = newAddress.Street,
                    Street2      = newAddress.Street2,
                    City         = newAddress.City,
                    Postal       = newAddress.Postal
                };

                dbEnrollee.MailingAddress = address;
            }
        }
Exemplo n.º 27
0
 public DataModel.Response.BaseResponse UpdateMailingAddress(DataModel.Model.MailingAddressModel mailing)
 {
     try
     {
         IMailingAddressRepository mailingRepository = RepositoryClassFactory.GetInstance().GetMailingAddressRepository();
         MailingAddress            _mailing          = MapperUtil.CreateMapper().Mapper.Map <MailingAddressModel, MailingAddress>(mailing);
         mailingRepository.Update(_mailing);
         return(new BaseResponse
         {
             ErrorCode = (int)ErrorCode.None,
             Message = Resources.Resource.msg_update_success
         });
     }
     catch (Exception ex)
     {
         return(new BaseResponse
         {
             ErrorCode = (int)ErrorCode.Error,
             Message = ex.Message
         });
     }
 }
Exemplo n.º 28
0
 public DataModel.Response.FindItemReponse <DataModel.Model.MailingAddressModel> FindMailingAddressByID(string Id)
 {
     try
     {
         IMailingAddressRepository mailingRepository = RepositoryClassFactory.GetInstance().GetMailingAddressRepository();
         MailingAddress            mailing           = mailingRepository.FindByID(Id);
         var _mailing = MapperUtil.CreateMapper().Mapper.Map <MailingAddress, MailingAddressModel>(mailing);
         return(new FindItemReponse <MailingAddressModel>
         {
             Item = _mailing,
             ErrorCode = (int)ErrorCode.None,
             Message = string.Empty
         });
     }
     catch (Exception ex)
     {
         return(new FindItemReponse <MailingAddressModel>
         {
             ErrorCode = (int)ErrorCode.Error,
             Message = ex.Message
         });
     }
 }
Exemplo n.º 29
0
        public IActionResult Pay(MailingAddress MailAddress)
        {
            MailAddress.CoustmerId = 1;
            if (ModelState.IsValid)
            {
                if (db_context.MailingAddress.Where(o => o.MailingAddressId == MailAddress.MailingAddressId).Count() > 0)
                {
                    MailingAddress ma = db_context.MailingAddress.Where(o => o.MailingAddressId == MailAddress.MailingAddressId).FirstOrDefault();
                    ma.AptNo   = MailAddress.AptNo;
                    ma.City    = MailAddress.City;
                    ma.Street  = MailAddress.Street;
                    ma.State   = MailAddress.State;
                    ma.ZipCode = MailAddress.ZipCode;
                }
                else
                {
                    db_context.MailingAddress.Add(MailAddress);
                }
                foreach (CartToys ct in db_context.CartToys.Where(o => o.CoustmerId == 1))
                {
                    PurchaseHistory ph = new PurchaseHistory();
                    ph.ToyId      = ct.ToyId;
                    ph.CoustmerId = ct.CoustmerId;
                    ph.Quantity   = ct.Quantity;
                    db_context.PurchaseHistory.Add(ph);
                    db_context.CartToys.Remove(ct);
                }

                db_context.SaveChanges();
                return(RedirectToAction("PurchaseHis"));
            }
            else
            {
                return(View("Purchase"));
            }
        }
Exemplo n.º 30
0
        public void FillFormForOthers(string examinationPosition, string appleant, string fName, string mName, string lName, string aka,
                                      string lastFourSSN, string contactPhone, string mailingAddress, string city, string state, string zip,
                                      string email, string cEmail, string empNumber, string payroll, string department, string appealIssue,
                                      string remedy
                                      )
        {
            // SubmitAppeal.Clicks();
            BtnIAgree.Clicks();

            OtherHeadingID.Clicks();
            Others.Clicks();

            if (appleant == "Yourself")
            {
                FillingYourSelf.Click();
            }
            FName.EnterText(fName);
            MName.EnterText(mName);
            LName.EnterText(lName);
            Aka.EnterText(aka);
            LastFourSSN.EnterText(lastFourSSN);
            ContactPhone.EnterText(contactPhone);
            MailingAddress.EnterText(mailingAddress);
            City.EnterText(city);
            State.ClearText(state);
            ZipCode.EnterText(zip);
            PreferredEmail.EnterText(email);
            ConfirmEmail.EnterText(cEmail);
            EmployeeNumber.EnterText(empNumber);
            Payroll.EnterText(payroll);
            EmployingDepartment.EnterText(department);
            AppealIssue.EnterText(appealIssue);
            Remedy.SendKeys(remedy);
            SubmitBtn.Clicks();
            AcceptPopupBtn.Clicks();
        }
        public async Task <IActionResult> Create(MailingAddressViewModel model)
        {
            if (ModelState.IsValid)
            {
                var             userId = _userManager.GetUserId(HttpContext.User);
                ApplicationUser user   = await _userManager.FindByIdAsync(userId);

                user.IsAdmin = false;
                var newAddress = new MailingAddress
                {
                    FirstName        = model.FirstName,
                    LastName         = model.LastName,
                    Company          = model.Company,
                    Address1         = model.Address1,
                    Address2         = model.Address2,
                    Country          = model.Country,
                    Province         = model.Province,
                    City             = model.City,
                    PostalCode       = model.PostalCode,
                    PhoneNumber      = model.PhoneNumber,
                    IsDefaultAddress = model.IsDefaultAddress,
                    CustomerId       = userId,
                };

                _context.MailingAddresses.Add(newAddress);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", "Customer"));

                /*
                 * List<MailingAddress> a = new List<MailingAddress>();
                 * if (user.MailingAddresses != null)
                 * {
                 *  var newOne = new List<MailingAddress> { new MailingAddress()
                 *  {FirstName = model.FirstName,
                 *  LastName = model.LastName,
                 *  Company = model.Company,
                 *  Address1 = model.Address1,
                 *  Address2 = model.Address2,
                 *  Country = model.Country,
                 *  Province = model.Province,
                 *  City = model.City,
                 *  PostalCode = model.PostalCode,
                 *  PhoneNumber = model.PhoneNumber,
                 *  IsDefaultAddress = model.IsDefaultAddress,
                 *  CustomerId = userId,} };
                 *  user.MailingAddresses = newOne;
                 *  user.PhoneNumber = newAddress.PhoneNumber.ToString();
                 * }
                 * else
                 * {
                 *  var newOne = new List<MailingAddress> { new MailingAddress()
                 *  { Id = newAddress.Id, } };
                 *  user.MailingAddresses = newOne;
                 *  user.PhoneNumber = newAddress.PhoneNumber.ToString();
                 * }*
                 * IdentityResult result = await _userManager.UpdateAsync(user);
                 * await _context.SaveChangesAsync();
                 * if (result.Succeeded)
                 * {
                 *  return RedirectToAction("Index", "Customer");
                 * }
                 * else
                 * {
                 *  foreach (var error in result.Errors)
                 *  {
                 *      ModelState.AddModelError(string.Empty, error.Description);
                 *  }
                 *  return View(model);
                 * }*/
            }
            return(View(model));
        }
        /// <summary>
        /// Get distances between multiple origin adresseses and a single destination address
        /// </summary>
        /// <param name="OriginAddresses">Origin adresses to calculate distance FROM</param>
        /// <param name="DestinationAddress">Destination adresses to calculate distances TO</param>
        /// <param name="mode">Transportation mode to calculate distances for</param>
        /// <param name="transitDate">Optional transit date, defaults to next monday at 3 PM</param>
        public static List <DistanceMatrixResult> CalculateDistances(List <MailingAddress> OriginAddresses, MailingAddress DestinationAddress, TransportationMode mode, DateTime?transitDate = null)
        {
            var originAddressesAsStringList = OriginAddresses.Where(o => o != null).Select(o => o.FullAddress).ToList();

            var responseObject = GetDistanceMatrixResult(originAddressesAsStringList, DestinationAddress.FullAddress, mode, transitDate);

            var results = new List <DistanceMatrixResult>();

            for (var i = 0; i < OriginAddresses.Count(); i++)
            {
                var row     = responseObject.rows.ElementAt(i);
                var element = row.elements.FirstOrDefault();

                if (element.status == "OK")
                {
                    results.Add(new DistanceMatrixResult()
                    {
                        Mode = mode,
                        DistanceInKilometers = (decimal)element.distance.value / 1000,
                        Duration             = TimeSpan.FromSeconds(element.duration.value),
                        DestinationAddressId = DestinationAddress.ID,
                        OriginAddressId      = OriginAddresses.ElementAt(i).ID,
                        DestinationAddress   = DestinationAddress.FullAddress,
                        OriginAddress        = OriginAddresses.ElementAt(i).FullAddress
                    });
                }
                else
                {
                    results.Add(new DistanceMatrixResult()
                    {
                        ErrorCode            = element.status,
                        Mode                 = TransportationMode.Unknown,
                        DestinationAddressId = DestinationAddress.ID,
                        OriginAddressId      = OriginAddresses.ElementAt(i).ID,
                        DestinationAddress   = DestinationAddress.FullAddress,
                        OriginAddress        = OriginAddresses.ElementAt(i).FullAddress
                    });
                }
            }
            return(results);
        }
Exemplo n.º 33
0
 private static Person MoveHomeAddress(this Person person, MailingAddress homeAddress)
 {
    return person
       .WithHomeAddress(homeAddress);
 }