示例#1
0
        public async Task <IActionResult> Edit(int id, [Bind("BusinessEntityId,AddressId,AddressTypeId,Rowguid,ModifiedDate")] BusinessEntityAddress businessEntityAddress)
        {
            if (id != businessEntityAddress.BusinessEntityId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(businessEntityAddress);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BusinessEntityAddressExists(businessEntityAddress.BusinessEntityId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AddressId"]        = new SelectList(_context.Address, "AddressId", "AddressLine1", businessEntityAddress.AddressId);
            ViewData["AddressTypeId"]    = new SelectList(_context.AddressType, "AddressTypeId", "Name", businessEntityAddress.AddressTypeId);
            ViewData["BusinessEntityId"] = new SelectList(_context.BusinessEntity, "BusinessEntityId", "BusinessEntityId", businessEntityAddress.BusinessEntityId);
            return(View(businessEntityAddress));
        }
        // POST: odata/BusinessEntityAddresses
        public IHttpActionResult Post(BusinessEntityAddress businessEntityAddress)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _db.BusinessEntityAddresses.Add(businessEntityAddress);

            try
            {
                _db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (BusinessEntityAddressExists(businessEntityAddress.BusinessEntityID))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(Created(businessEntityAddress));
        }
 public ActionResult Edit([Bind(Include = "BusinessEntityID,AddressID,AddressTypeID,rowguid,ModifiedDate")] BusinessEntityAddress businessEntityAddress)
 {
     if (ModelState.IsValid)
     {
         db.Entry(businessEntityAddress).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.AddressID = new SelectList(db.Addresses, "AddressID", "AddressLine1", businessEntityAddress.AddressID);
     return(View(businessEntityAddress));
 }
        // PUT api/awbuildversion/5
        public void Put(BusinessEntityAddress value)
        {
            var GetActionType = Request.Headers.Where(x => x.Key.Equals("ActionType")).FirstOrDefault();

            if (GetActionType.Key != null)
            {
                if (GetActionType.Value.ToList()[0].Equals("DELETE"))
                    adventureWorks_BC.BusinessEntityAddressDelete(value);
                if (GetActionType.Value.ToList()[0].Equals("UPDATE"))
                    adventureWorks_BC.BusinessEntityAddressUpdate(value);
            }
        }
        public bool Insert(BusinessEntityAddress businessentityaddress)
        {
            int autonumber = 0;
            BusinessEntityAddressDAC businessentityaddressComponent = new BusinessEntityAddressDAC();
            bool endedSuccessfuly = businessentityaddressComponent.InsertNewBusinessEntityAddress(ref autonumber, businessentityaddress.BusinessEntityId, businessentityaddress.AddressId, businessentityaddress.AddressTypeId, businessentityaddress.RowGuid, businessentityaddress.ModifiedDate);

            if (endedSuccessfuly)
            {
                businessentityaddress.BusinessEntityAddressId = autonumber;
            }
            return(endedSuccessfuly);
        }
示例#6
0
        public void CreatePerson(PersonDTO personDTO)
        {
            var busEntity = new BusinessEntity()
            {
                rowguid      = Guid.NewGuid(),
                ModifiedDate = DateTime.Now
            };

            var personCurrent = new Person()
            {
                FirstName      = personDTO.FirstName,
                MiddleName     = personDTO.MiddleName,
                LastName       = personDTO.LastName,
                EmailPromotion = 0,
                rowguid        = Guid.NewGuid(),
                ModifiedDate   = DateTime.Now
            };

            var busEntityAddress = new BusinessEntityAddress()
            {
                AddressTypeID = 2,
                rowguid       = Guid.NewGuid(),
                ModifiedDate  = DateTime.Now
            };

            var stateProvince = unitOfWork.StateProvince.GetList(i => i.CountryRegionCode == personDTO.Country.ToString()).FirstOrDefault();

            var address = new Address()
            {
                AddressLine1  = personDTO.Address,
                City          = personDTO.City,
                StateProvince = stateProvince,
                PostalCode    = personDTO.PostalCode,
                rowguid       = Guid.NewGuid(),
                ModifiedDate  = DateTime.Now
            };


            busEntity.BusinessEntityAddresses.Add(busEntityAddress);

            address.BusinessEntityAddresses.Add(busEntityAddress);

            personCurrent.BusinessEntity = busEntity;

            personCurrent.UserID = personDTO.UserId;

            unitOfWork.Address.Create(address);

            unitOfWork.Person.Create(personCurrent);

            unitOfWork.Save();
        }
示例#7
0
        public virtual BusinessEntityAddress MapBOToEF(
            BOBusinessEntityAddress bo)
        {
            BusinessEntityAddress efBusinessEntityAddress = new BusinessEntityAddress();

            efBusinessEntityAddress.SetProperties(
                bo.AddressID,
                bo.AddressTypeID,
                bo.BusinessEntityID,
                bo.ModifiedDate,
                bo.Rowguid);
            return(efBusinessEntityAddress);
        }
示例#8
0
        public virtual BOBusinessEntityAddress MapEFToBO(
            BusinessEntityAddress ef)
        {
            var bo = new BOBusinessEntityAddress();

            bo.SetProperties(
                ef.BusinessEntityID,
                ef.AddressID,
                ef.AddressTypeID,
                ef.ModifiedDate,
                ef.Rowguid);
            return(bo);
        }
示例#9
0
        public async Task <IActionResult> Create([Bind("BusinessEntityId,AddressId,AddressTypeId,Rowguid,ModifiedDate")] BusinessEntityAddress businessEntityAddress)
        {
            if (ModelState.IsValid)
            {
                _context.Add(businessEntityAddress);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AddressId"]        = new SelectList(_context.Address, "AddressId", "AddressLine1", businessEntityAddress.AddressId);
            ViewData["AddressTypeId"]    = new SelectList(_context.AddressType, "AddressTypeId", "Name", businessEntityAddress.AddressTypeId);
            ViewData["BusinessEntityId"] = new SelectList(_context.BusinessEntity, "BusinessEntityId", "BusinessEntityId", businessEntityAddress.BusinessEntityId);
            return(View(businessEntityAddress));
        }
示例#10
0
 public bool BusinessEntityAddressDelete(BusinessEntityAddress businessentityaddress)
 {
     return(Execute <bool>(dal =>
     {
         BusinessEntityAddress businessentityaddressDelete = dal.BusinessEntityAddress.Where(x => x.BusinessEntityID == businessentityaddress.BusinessEntityID).FirstOrDefault();
         if (businessentityaddressDelete != null)
         {
             dal.BusinessEntityAddress.DeleteOnSubmit(businessentityaddressDelete);
             dal.SubmitChanges();
             return true;
         }
         return false;
     }));
 }
        public void MapEFToBOList()
        {
            var mapper = new DALBusinessEntityAddressMapper();
            BusinessEntityAddress entity = new BusinessEntityAddress();

            entity.SetProperties(1, 1, 1, DateTime.Parse("1/1/1987 12:00:00 AM"), Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"));

            List <BOBusinessEntityAddress> response = mapper.MapEFToBO(new List <BusinessEntityAddress>()
            {
                entity
            });

            response.Count.Should().Be(1);
        }
        // DELETE: odata/BusinessEntityAddresses(5)
        public IHttpActionResult Delete([FromODataUri] int key)
        {
            BusinessEntityAddress businessEntityAddress = _db.BusinessEntityAddresses.Find(key);

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

            _db.BusinessEntityAddresses.Remove(businessEntityAddress);
            _db.SaveChanges();

            return(StatusCode(HttpStatusCode.NoContent));
        }
        // GET: BusinessEntityAddresses/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BusinessEntityAddress businessEntityAddress = db.BusinessEntityAddresses.Find(id);

            if (businessEntityAddress == null)
            {
                return(HttpNotFound());
            }
            return(View(businessEntityAddress));
        }
        public void MapEFToBO()
        {
            var mapper = new DALBusinessEntityAddressMapper();
            BusinessEntityAddress entity = new BusinessEntityAddress();

            entity.SetProperties(1, 1, 1, DateTime.Parse("1/1/1987 12:00:00 AM"), Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"));

            BOBusinessEntityAddress response = mapper.MapEFToBO(entity);

            response.AddressID.Should().Be(1);
            response.AddressTypeID.Should().Be(1);
            response.BusinessEntityID.Should().Be(1);
            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Rowguid.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"));
        }
        // GET: BusinessEntityAddresses/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BusinessEntityAddress businessEntityAddress = db.BusinessEntityAddresses.Find(id);

            if (businessEntityAddress == null)
            {
                return(HttpNotFound());
            }
            ViewBag.AddressID = new SelectList(db.Addresses, "AddressID", "AddressLine1", businessEntityAddress.AddressID);
            return(View(businessEntityAddress));
        }
        // PUT api/awbuildversion/5
        public void Put(BusinessEntityAddress value)
        {
            var GetActionType = Request.Headers.Where(x => x.Key.Equals("ActionType")).FirstOrDefault();

            if (GetActionType.Key != null)
            {
                if (GetActionType.Value.ToList()[0].Equals("DELETE"))
                {
                    adventureWorks_BC.BusinessEntityAddressDelete(value);
                }
                if (GetActionType.Value.ToList()[0].Equals("UPDATE"))
                {
                    adventureWorks_BC.BusinessEntityAddressUpdate(value);
                }
            }
        }
示例#17
0
        private void InsertAddress(ShoppingDetails shoppingDetails, int businessEntityID)
        {
            ShoppingAddress shoppingAddress = new ShoppingAddress();
            ShoppingDetails details         = shoppingAddress.Get(businessEntityID);

            if (!details.Equals(shoppingDetails))
            {
                using (var context = new AWContext())
                {
                    var customerAddress = new Address()
                    {
                        AddressLine1    = shoppingDetails.Address, City = shoppingDetails.City,
                        StateProvinceID = shoppingAddress.GetStateProvince(shoppingDetails.City, shoppingDetails.Country),
                        PostalCode      = shoppingDetails.PostalCode, ModifiedDate = DateTime.Now,
                        rowguid         = Guid.NewGuid()
                    };
                    if (details.Address != null) //update
                    {
                        var addressID = context.BusinessEntityAddress.SingleOrDefault(x => x.BusinessEntityID == businessEntityID).AddressID;
                        var result    = context.Address.SingleOrDefault(x => x.AddressID == addressID);
                        result.AddressLine1    = customerAddress.AddressLine1;
                        result.City            = customerAddress.City;
                        result.StateProvinceID = customerAddress.StateProvinceID;
                        result.PostalCode      = customerAddress.PostalCode;
                        result.ModifiedDate    = customerAddress.ModifiedDate;
                        result.rowguid         = customerAddress.rowguid;
                        context.SaveChanges();
                    }
                    else // insert
                    {
                        var businessEntity = new BusinessEntityAddress()
                        {
                            BusinessEntityID = businessEntityID,
                            AddressTypeID    = 1,
                            ModifiedDate     = DateTime.Now,
                            rowguid          = Guid.NewGuid()
                        };
                        context.Address.Add(customerAddress);
                        context.SaveChanges();

                        businessEntity.AddressID = customerAddress.AddressID;
                        context.BusinessEntityAddress.Add(businessEntity);
                        context.SaveChanges();
                    }
                }
            }
        }
        public override Vendor PopulateRecord(SqlDataReader reader)
        {
            AddressType addressType = new AddressType
            {
                Name = reader["AddressType"].ToString()
            };

            CountryRegion country = new CountryRegion
            {
                Name = reader["CountryRegionName"].ToString()
            };

            StateProvince state = new StateProvince
            {
                Name          = reader["StateProvinceName"].ToString(),
                CountryRegion = country
            };

            Address _address = new Address
            {
                AddressLine1  = reader["AddressLine1"].ToString(),
                AddressLine2  = reader["AddressLine2"].ToString(),
                City          = reader["City"].ToString(),
                PostalCode    = reader["PostalCode"].ToString(),
                StateProvince = state
            };
            BusinessEntityAddress entityAddress = new BusinessEntityAddress
            {
                Address     = _address,
                AddressType = addressType
            };

            return(new Vendor
            {
                BusinessEntityID = Convert.ToInt32((int)reader["BusinessEntityID"]),
                Name = reader["Name"].ToString(),
                AccountNumber = reader["AccountNumber"].ToString(),
                CreditRating = (byte)reader["CreditRating"],
                PreferredVendorStatus = (bool)reader["PreferredVendorStatus"],
                ActiveFlag = (bool)reader["ActiveFlag"],
                PurchasingWebServiceURL = reader["PurchasingWebServiceURL"].ToString(),
                ModifiedDate = (DateTime)reader["ModifiedDate"],
                VendorReps = GetVendorReps(Convert.ToInt32((int)reader["BusinessEntityID"])),
                BusinessEntityAddress = entityAddress
            });
        }
        public async void Get()
        {
            var mock   = new ServiceMockFacade <IBusinessEntityAddressRepository>();
            var record = new BusinessEntityAddress();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(record));
            var service = new BusinessEntityAddressService(mock.LoggerMock.Object,
                                                           mock.RepositoryMock.Object,
                                                           mock.ModelValidatorMockFactory.BusinessEntityAddressModelValidatorMock.Object,
                                                           mock.BOLMapperMockFactory.BOLBusinessEntityAddressMapperMock,
                                                           mock.DALMapperMockFactory.DALBusinessEntityAddressMapperMock);

            ApiBusinessEntityAddressResponseModel response = await service.Get(default(int));

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            var res = (from c in db.BusinessEntityAddresses
                       where c.BusinessEntityID == id
                       select c).FirstOrDefault();

            if (res != null)
            {
                res.isDeleted = true;
                db.SaveChanges();
                ViewBag.Message = string.Format("Congrats! Delete success");
            }

            BusinessEntityAddress businessEntity = db.BusinessEntityAddresses.Find(id);



            return(View(businessEntity));
        }
示例#21
0
        public bool BusinessEntityAddressUpdate(BusinessEntityAddress businessentityaddress)
        {
            return(Execute <bool>(dal =>
            {
                BusinessEntityAddress businessentityaddressUpdate = dal.BusinessEntityAddress.Where(x => x.BusinessEntityID == businessentityaddress.BusinessEntityID).FirstOrDefault();
                if (businessentityaddressUpdate != null)
                {
                    businessentityaddressUpdate.BusinessEntityID = businessentityaddress.BusinessEntityID;
                    businessentityaddressUpdate.AddressID = businessentityaddress.AddressID;
                    businessentityaddressUpdate.AddressTypeID = businessentityaddress.AddressTypeID;
                    businessentityaddressUpdate.rowguid = businessentityaddress.rowguid;
                    businessentityaddressUpdate.ModifiedDate = businessentityaddress.ModifiedDate;

                    dal.SubmitChanges();
                    return true;
                }
                return false;
            }));
        }
        // PUT: odata/BusinessEntityAddresses(5)
        public IHttpActionResult Put([FromODataUri] int key, Delta <BusinessEntityAddress> patch)
        {
            Validate(patch.GetInstance());

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            BusinessEntityAddress businessEntityAddress = _db.BusinessEntityAddresses.Find(key);

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

            patch.Put(businessEntityAddress);

            try
            {
                _db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BusinessEntityAddressExists(key))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Updated(businessEntityAddress));
        }
        public bool Update(BusinessEntityAddress businessentityaddress, int old_businessEntityAddressId)
        {
            BusinessEntityAddressDAC businessentityaddressComponent = new BusinessEntityAddressDAC();

            return(businessentityaddressComponent.UpdateBusinessEntityAddress(businessentityaddress.BusinessEntityId, businessentityaddress.AddressId, businessentityaddress.AddressTypeId, businessentityaddress.RowGuid, businessentityaddress.ModifiedDate, old_businessEntityAddressId));
        }
 // POST api/awbuildversion
 public void Post(BusinessEntityAddress value)
 {
     adventureWorks_BC.BusinessEntityAddressAdd(value);
 }
        public List <BusinessEntityAddress> GetAllByPersonId(int PersonId)
        {
            BusinessEntityAddressDAC _businessEntityAddressComponent = new BusinessEntityAddressDAC();
            IDataReader reader = _businessEntityAddressComponent.GetAllBusinessEntityAddress(" BusinessEntityId = " + PersonId).CreateDataReader();
            List <BusinessEntityAddress> _businessEntityAddressList = new List <BusinessEntityAddress>();

            while (reader.Read())
            {
                if (_businessEntityAddressList == null)
                {
                    _businessEntityAddressList = new List <BusinessEntityAddress>();
                }
                BusinessEntityAddress _businessEntityAddress = new BusinessEntityAddress();
                if (reader["BusinessEntityAddressId"] != DBNull.Value)
                {
                    _businessEntityAddress.BusinessEntityAddressId = Convert.ToInt32(reader["BusinessEntityAddressId"]);
                }
                if (reader["BusinessEntityId"] != DBNull.Value)
                {
                    _businessEntityAddress.BusinessEntityId = Convert.ToInt32(reader["BusinessEntityId"]);
                }
                if (reader["AddressId"] != DBNull.Value)
                {
                    _businessEntityAddress.AddressId = Convert.ToInt32(reader["AddressId"]);
                }
                if (reader["AddressTypeId"] != DBNull.Value)
                {
                    _businessEntityAddress.AddressTypeId = Convert.ToInt32(reader["AddressTypeId"]);
                }
                if (reader["RowGuid"] != DBNull.Value)
                {
                    _businessEntityAddress.RowGuid = new Guid(reader["RowGuid"].ToString());
                }
                if (reader["ModifiedDate"] != DBNull.Value)
                {
                    _businessEntityAddress.ModifiedDate = Convert.ToDateTime(reader["ModifiedDate"]);
                }
                if (reader["AddressLine1"] != DBNull.Value)
                {
                    _businessEntityAddress.AddressLine1 = Convert.ToString(reader["AddressLine1"]);
                }
                if (reader["AddressLine2"] != DBNull.Value)
                {
                    _businessEntityAddress.AddressLine2 = Convert.ToString(reader["AddressLine2"]);
                }
                if (reader["AddressLine3"] != DBNull.Value)
                {
                    _businessEntityAddress.AddressLine3 = Convert.ToString(reader["AddressLine3"]);
                }
                if (reader["CountryRegionCode"] != DBNull.Value)
                {
                    _businessEntityAddress.CountryRegionCode = Convert.ToString(reader["CountryRegionCode"]);
                }
                if (reader["City"] != DBNull.Value)
                {
                    _businessEntityAddress.City = Convert.ToString(reader["City"]);
                }
                if (reader["StateProvinceId"] != DBNull.Value)
                {
                    _businessEntityAddress.StateProvinceId = Convert.ToInt32(reader["StateProvinceId"]);
                }
                if (reader["PostalCode"] != DBNull.Value)
                {
                    _businessEntityAddress.PostalCode = Convert.ToString(reader["PostalCode"]);
                }
                if (reader["ZipCode"] != DBNull.Value)
                {
                    _businessEntityAddress.ZipCode = Convert.ToString(reader["ZipCode"]);
                }
                if (reader["SpatialLocation"] != DBNull.Value)
                {
                    _businessEntityAddress.SpatialLocation = Convert.ToString(reader["SpatialLocation"]);
                }
                if (reader["CountryName"] != DBNull.Value)
                {
                    _businessEntityAddress.CountryName = Convert.ToString(reader["CountryName"]);
                }
                _businessEntityAddress.NewRecord = false;
                _businessEntityAddressList.Add(_businessEntityAddress);
            }
            reader.Close();
            return(_businessEntityAddressList);
        }
        public override Store PopulateRecord(SqlDataReader reader)
        {
            AddressType addressType = new AddressType
            {
                Name = reader["AddressType"].ToString()
            };

            CountryRegion country = new CountryRegion
            {
                Name = reader["CountryRegionName"].ToString()
            };

            StateProvince state = new StateProvince
            {
                Name          = reader["StateProvinceName"].ToString(),
                CountryRegion = country
            };

            Address _address = new Address
            {
                AddressLine1  = reader["AddressLine1"].ToString(),
                AddressLine2  = reader["AddressLine2"].ToString(),
                City          = reader["City"].ToString(),
                PostalCode    = reader["PostalCode"].ToString(),
                StateProvince = state
            };
            BusinessEntityAddress entityAddress = new BusinessEntityAddress
            {
                Address     = _address,
                AddressType = addressType
            };


            EmailAddress emailAddress = new EmailAddress
            {
                EmailAddress1 = (string)reader["EmailAddress"]
            };

            PhoneNumberType numberType = new PhoneNumberType
            {
                Name = reader["PhoneType"].ToString(),
            };

            PersonPhone phone = new PersonPhone
            {
                PhoneNumber       = (string)reader["PhoneNumber"],
                PhoneNumberTypeID = Convert.ToInt32((int)reader["PhoneNumberTypeID"]),
                PhoneNumberType   = numberType
            };

            SalesPerson salesPerson = new SalesPerson
            {
                BusinessEntityID = Convert.ToInt32((int)reader["SPBusinessEntityID"]),
                FirstName        = reader["FirstName"].ToString(),
                MiddleName       = reader["MiddleName"].ToString(),
                LastName         = reader["LastName"].ToString(),
                EmailAddress     = emailAddress,
                PersonPhone      = phone
            };

            Customer customer = new Customer
            {
                AccountNumber = reader["AccountNumber"].ToString()
            };

            StoreDemographics demographics = new StoreDemographics
            {
                ID              = Convert.ToInt32((int)reader["BusinessEntityID"]),
                AnnualRevenue   = Convert.ToDecimal((decimal)reader["AnnualRevenue"]),
                AnnualSales     = Convert.ToDecimal((decimal)reader["AnnualSales"]),
                BankName        = reader["BankName"].ToString(),
                BusinessType    = reader["BusinessType"].ToString(),
                YearOpened      = Convert.ToInt32((int)reader["YearOpened"]),
                Speciality      = reader["Specialty"].ToString(),
                SquareFeet      = Convert.ToInt32((int)reader["SquareFeet"]),
                Brands          = reader["Brands"].ToString(),
                Internet        = reader["Internet"].ToString(),
                NumberEmployees = Convert.ToInt32((int)reader["NumberEmployees"])
            };

            return(new Store
            {
                BusinessEntityID = Convert.ToInt32((int)reader["BusinessEntityID"]),
                Name = reader["Name"].ToString(),
                SalesPersonID = Convert.ToInt32((int)reader["SalesPersonID"]),
                Demographics = reader["Demographics"].ToString(),
                rowguid = (Guid)reader["rowguid"],
                ModifiedDate = (DateTime)reader["ModifiedDate"],
                SalesPerson = salesPerson,
                StoreReps = GetStorerReps(Convert.ToInt32((int)reader["BusinessEntityID"])),
                Customer = customer,
                BusinessEntityAddress = entityAddress,
                StoreDemographics = demographics
            });
        }
 // POST api/awbuildversion
 public void Post(BusinessEntityAddress value)
 {
     adventureWorks_BC.BusinessEntityAddressAdd(value);
 }
示例#28
0
        private async Task <int> CreateClient(RegisDTO registerDto)
        {
            using (DbContextTransaction transaction = _uow.Context.Database.BeginTransaction())
            {
                try
                {
                    var bEntity = new BusinessEntity()
                    {
                        ModifiedDate = DateTime.Now, rowguid = Guid.NewGuid()
                    };
                    _uow.BusinessEntity.Create(bEntity);
                    await _uow.Save();

                    var person = new Person {
                        BusinessEntityID = bEntity.BusinessEntityID,
                        PersonType       = "GC",
                        FirstName        = registerDto.FirstName,
                        LastName         = registerDto.LastName,
                        rowguid          = Guid.NewGuid(),
                        ModifiedDate     = DateTime.Now
                    };
                    _uow.Person.Create(person);
                    await _uow.Save();

                    var address = new Address {
                        AddressLine1    = registerDto.Address,
                        City            = registerDto.City,
                        StateProvinceID = registerDto.StateProvinceID,
                        PostalCode      = registerDto.PostalCode,
                        rowguid         = Guid.NewGuid(),
                        ModifiedDate    = DateTime.Now
                    };
                    _uow.Address.Create(address);
                    await _uow.Save();

                    var bEntityAddress = new BusinessEntityAddress
                    {
                        BusinessEntityID = bEntity.BusinessEntityID,
                        AddressTypeID    = 2,
                        AddressID        = address.AddressID,
                        ModifiedDate     = DateTime.Now,
                        rowguid          = Guid.NewGuid()
                    };
                    _uow.BusinessEntityAddress.Create(bEntityAddress);
                    await _uow.Save();

                    _uow.Customer.Create(new Customer {
                        PersonID     = person.BusinessEntityID,
                        TerritoryID  = registerDto.StateProvinceID,
                        rowguid      = Guid.NewGuid(),
                        ModifiedDate = DateTime.Now
                    });;
                    await _uow.Save();

                    transaction.Commit();

                    return(bEntity.BusinessEntityID);
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    throw ex;
                }
            }
        }
        public BusinessEntity CreateCurrentCustomer(ShippingDetailsDTO shippingDetails)
        {
            var busEntity = new BusinessEntity()
            {
                rowguid      = Guid.NewGuid(),
                ModifiedDate = DateTime.Now
            };

            var personCurrent = new Person()
            {
                FirstName      = shippingDetails.FirstName,
                MiddleName     = shippingDetails.MiddleName,
                LastName       = shippingDetails.LastName,
                EmailPromotion = 0,
                rowguid        = Guid.NewGuid(),
                ModifiedDate   = DateTime.Now
            };

            var busEntityAddress = new BusinessEntityAddress()
            {
                AddressTypeID = 2,
                rowguid       = Guid.NewGuid(),
                ModifiedDate  = DateTime.Now
            };

            var stateProvince = unitOfWork.StateProvince.GetList(i => i.CountryRegionCode == shippingDetails.Country.ToString()).FirstOrDefault();

            var address = new Address()
            {
                AddressLine1  = shippingDetails.Address,
                City          = shippingDetails.City,
                StateProvince = stateProvince,
                PostalCode    = shippingDetails.PostalCode,
                rowguid       = Guid.NewGuid(),
                ModifiedDate  = DateTime.Now
            };

            var personPhone = new PersonPhone()
            {
                PhoneNumber       = shippingDetails.MobilePhone,
                PhoneNumberTypeID = 1,
                ModifiedDate      = DateTime.Now
            };

            var emailAddress = new EmailAddress()
            {
                EmailAddress1 = shippingDetails.Email,
                rowguid       = Guid.NewGuid(),
                ModifiedDate  = DateTime.Now
            };

            busEntity.BusinessEntityAddresses.Add(busEntityAddress);

            address.BusinessEntityAddresses.Add(busEntityAddress);

            personCurrent.BusinessEntity = busEntity;

            personCurrent.EmailAddresses.Add(emailAddress);

            personCurrent.PersonPhones.Add(personPhone);

            unitOfWork.Address.Create(address);

            unitOfWork.Person.Create(personCurrent);

            unitOfWork.Save();

            return(busEntity);
        }
        public BusinessEntityAddress GetByID(int _businessEntityAddressId)
        {
            BusinessEntityAddressDAC _businessEntityAddressComponent = new BusinessEntityAddressDAC();
            IDataReader           reader = _businessEntityAddressComponent.GetByIDBusinessEntityAddress(_businessEntityAddressId);
            BusinessEntityAddress _businessEntityAddress = null;

            while (reader.Read())
            {
                _businessEntityAddress = new BusinessEntityAddress();
                if (reader["BusinessEntityAddressId"] != DBNull.Value)
                {
                    _businessEntityAddress.BusinessEntityAddressId = Convert.ToInt32(reader["BusinessEntityAddressId"]);
                }
                if (reader["BusinessEntityId"] != DBNull.Value)
                {
                    _businessEntityAddress.BusinessEntityId = Convert.ToInt32(reader["BusinessEntityId"]);
                }
                if (reader["AddressId"] != DBNull.Value)
                {
                    _businessEntityAddress.AddressId = Convert.ToInt32(reader["AddressId"]);
                }
                if (reader["AddressTypeId"] != DBNull.Value)
                {
                    _businessEntityAddress.AddressTypeId = Convert.ToInt32(reader["AddressTypeId"]);
                }
                if (reader["RowGuid"] != DBNull.Value)
                {
                    _businessEntityAddress.RowGuid = new Guid(reader["RowGuid"].ToString());
                }
                if (reader["ModifiedDate"] != DBNull.Value)
                {
                    _businessEntityAddress.ModifiedDate = Convert.ToDateTime(reader["ModifiedDate"]);
                }
                if (reader["AddressLine1"] != DBNull.Value)
                {
                    _businessEntityAddress.AddressLine1 = Convert.ToString(reader["AddressLine1"]);
                }
                if (reader["AddressLine2"] != DBNull.Value)
                {
                    _businessEntityAddress.AddressLine2 = Convert.ToString(reader["AddressLine2"]);
                }
                if (reader["AddressLine3"] != DBNull.Value)
                {
                    _businessEntityAddress.AddressLine3 = Convert.ToString(reader["AddressLine3"]);
                }
                if (reader["CountryRegionCode"] != DBNull.Value)
                {
                    _businessEntityAddress.CountryRegionCode = Convert.ToString(reader["CountryRegionCode"]);
                }
                if (reader["City"] != DBNull.Value)
                {
                    _businessEntityAddress.City = Convert.ToString(reader["City"]);
                }
                if (reader["StateProvinceId"] != DBNull.Value)
                {
                    _businessEntityAddress.StateProvinceId = Convert.ToInt32(reader["StateProvinceId"]);
                }
                if (reader["PostalCode"] != DBNull.Value)
                {
                    _businessEntityAddress.PostalCode = Convert.ToString(reader["PostalCode"]);
                }
                if (reader["ZipCode"] != DBNull.Value)
                {
                    _businessEntityAddress.ZipCode = Convert.ToString(reader["ZipCode"]);
                }
                if (reader["SpatialLocation"] != DBNull.Value)
                {
                    _businessEntityAddress.SpatialLocation = Convert.ToString(reader["SpatialLocation"]);
                }
                if (reader["CountryName"] != DBNull.Value)
                {
                    _businessEntityAddress.CountryName = Convert.ToString(reader["CountryName"]);
                }
                _businessEntityAddress.NewRecord = false;
            }
            reader.Close();
            return(_businessEntityAddress);
        }
        public override IndividualCustomer PopulateRecord(SqlDataReader reader)
        {
            AddressType addressType = new AddressType
            {
                Name = reader["AddressType"].ToString()
            };

            CountryRegion country = new CountryRegion
            {
                Name = reader["CountryRegionName"].ToString()
            };

            StateProvince state = new StateProvince
            {
                Name          = reader["StateProvinceName"].ToString(),
                CountryRegion = country
            };

            Address _address = new Address
            {
                AddressLine1  = reader["AddressLine1"].ToString(),
                AddressLine2  = reader["AddressLine2"].ToString(),
                City          = reader["City"].ToString(),
                PostalCode    = reader["PostalCode"].ToString(),
                StateProvince = state
            };
            BusinessEntityAddress entityAddress = new BusinessEntityAddress
            {
                Address     = _address,
                AddressType = addressType
            };

            EmailAddress emailAddress = new EmailAddress
            {
                EmailAddress1 = (string)reader["EmailAddress"]
            };
            PhoneNumberType numberType = new PhoneNumberType
            {
                Name = reader["PhoneType"].ToString()
            };

            PersonPhone phone = new PersonPhone
            {
                PhoneNumber     = (string)reader["PhoneNumber"],
                PhoneNumberType = numberType
            };


            CreditCard credit = new CreditCard
            {
                CreditCardID = Convert.ToInt32((int)reader["CreditCardID"]),
                CardType     = reader["CardType"].ToString(),
                CardNumber   = reader["CardNumber"].ToString(),
                ExpMonth     = Convert.ToByte((byte)reader["ExpMonth"]),
                ExpYear      = Convert.ToInt16((short)reader["ExpYear"]),
            };

            PersonCreditCard personCreditCard = new PersonCreditCard
            {
                CreditCardID = Convert.ToInt32((int)reader["CreditCardID"]),
                CreditCard   = credit
            };

            Customer customer = new Customer
            {
                AccountNumber = reader["AccountNumber"].ToString()
            };

            return(new IndividualCustomer
            {
                BusinessEntityID = Convert.ToInt32((int)reader["BusinessEntityID"]),
                FirstName = reader["FirstName"].ToString(),
                MiddleName = reader["MiddleName"].ToString(),
                LastName = reader["LastName"].ToString(),
                Suffix = reader["Suffix"].ToString(),
                PersonType = reader["PersonType"].ToString(),
                NameStyle = (bool)reader["NameStyle"],
                Title = reader["Title"].ToString(),
                EmailPromotion = Convert.ToInt32((int)reader["EmailPromotion"]),
                ModifiedDate = (DateTime)reader["ModifiedDate"],
                rowguid = (Guid)reader["rowguid"],
                EmailAddress = emailAddress,
                PersonPhone = phone,
                BusinessEntityAddress = entityAddress,
                Customer = customer,
                PersonCreditCard = personCreditCard
            });
        }
        public override Employee PopulateRecord(SqlDataReader reader)
        {
            AddressType addressType = new AddressType
            {
                Name = reader["AddressType"].ToString()
            };

            CountryRegion country = new CountryRegion
            {
                Name = reader["CountryRegionName"].ToString()
            };

            StateProvince state = new StateProvince
            {
                Name          = reader["StateProvinceName"].ToString(),
                CountryRegion = country
            };

            Address _address = new Address
            {
                AddressLine1    = reader["AddressLine1"].ToString(),
                AddressLine2    = reader["AddressLine2"].ToString(),
                City            = reader["City"].ToString(),
                PostalCode      = reader["PostalCode"].ToString(),
                StateProvinceID = Convert.ToInt32((int)reader["StateProvinceID"]),
                StateProvince   = state
            };
            BusinessEntityAddress entityAddress = new BusinessEntityAddress
            {
                Address     = _address,
                AddressType = addressType
            };

            EmailAddress emailAddress = new EmailAddress
            {
                EmailAddress1 = (string)reader["EmailAddress"]
            };
            PhoneNumberType numberType = new PhoneNumberType
            {
                Name = reader["PhoneType"].ToString()
            };

            PersonPhone phone = new PersonPhone
            {
                PhoneNumber       = (string)reader["PhoneNumber"],
                PhoneNumberTypeID = Convert.ToInt32((int)reader["PhoneNumberTypeID"]),
                PhoneNumberType   = numberType
            };

            Shift shift = new Shift
            {
                Name      = reader["ShiftName"].ToString(),
                StartTime = (TimeSpan)reader["StartTime"],
                EndTime   = (TimeSpan)reader["EndTime"]
            };

            Department department = new Department
            {
                Name      = reader["Department"].ToString(),
                GroupName = reader["GroupName"].ToString()
            };

            EmployeeDepartmentHistory employeeDepartment = new EmployeeDepartmentHistory
            {
                ShiftID      = Convert.ToByte((byte)reader["ShiftID"]),
                DepartmentID = Convert.ToInt16((short)reader["DepartmentID"]),
                Department   = department,
                Shift        = shift
            };

            EmployeePayHistory employeePay = new EmployeePayHistory
            {
                Rate         = Convert.ToDecimal((decimal)reader["Rate"]),
                PayFrequency = Convert.ToByte((byte)reader["PayFrequency"])
            };

            return(new Employee
            {
                BusinessEntityID = Convert.ToInt32((int)reader["BusinessEntityID"]),
                FirstName = reader["FirstName"].ToString(),
                MiddleName = reader["MiddleName"].ToString(),
                LastName = reader["LastName"].ToString(),
                Suffix = reader["Suffix"].ToString(),
                PersonType = reader["PersonType"].ToString(),
                NameStyle = (bool)reader["NameStyle"],
                Title = reader["Title"].ToString(),
                EmailPromotion = Convert.ToInt32((int)reader["EmailPromotion"]),
                ModifiedDate = (DateTime)reader["ModifiedDate"],
                rowguid = (Guid)reader["rowguid"],

                NationalIDNumber = reader["NationalIDNumber"].ToString(),
                LoginID = reader["LoginID"].ToString(),
                JobTitle = reader["JobTitle"].ToString(),
                BirthDate = (DateTime)reader["BirthDate"],
                MaritalStatus = reader["MaritalStatus"].ToString(),
                Gender = reader["Gender"].ToString(),
                HireDate = (DateTime)reader["HireDate"],
                SalariedFlag = (bool)reader["SalariedFlag"],
                VacationHours = Convert.ToInt16((short)reader["VacationHours"]),
                SickLeaveHours = Convert.ToInt16((short)reader["SickLeaveHours"]),
                CurrentFlag = (bool)reader["CurrentFlag"],

                EmailAddress = emailAddress,
                PersonPhone = phone,
                BusinessEntityAddress = entityAddress,
                EmployeeDepartmentHistory = employeeDepartment,
                EmployeePayHistory = employeePay
            });
        }