// POST: odata/BusinessEntityContacts
        public IHttpActionResult Post(BusinessEntityContact businessEntityContact)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _db.BusinessEntityContacts.Add(businessEntityContact);

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

            return(Created(businessEntityContact));
        }
예제 #2
0
        public async Task <IActionResult> Edit(int id, [Bind("BusinessEntityId,PersonId,ContactTypeId,Rowguid,ModifiedDate")] BusinessEntityContact businessEntityContact)
        {
            if (id != businessEntityContact.BusinessEntityId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(businessEntityContact);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BusinessEntityContactExists(businessEntityContact.BusinessEntityId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BusinessEntityId"] = new SelectList(_context.BusinessEntity, "BusinessEntityId", "BusinessEntityId", businessEntityContact.BusinessEntityId);
            ViewData["ContactTypeId"]    = new SelectList(_context.ContactType, "ContactTypeId", "Name", businessEntityContact.ContactTypeId);
            ViewData["PersonId"]         = new SelectList(_context.Person, "BusinessEntityId", "FirstName", businessEntityContact.PersonId);
            return(View(businessEntityContact));
        }
        public BusinessEntityContact GetByID(int _personId)
        {
            BusinessEntityContactDAC _businessEntityContactComponent = new BusinessEntityContactDAC();
            IDataReader           reader = _businessEntityContactComponent.GetByIDBusinessEntityContact(_personId);
            BusinessEntityContact _businessEntityContact = null;

            while (reader.Read())
            {
                _businessEntityContact = new BusinessEntityContact();
                if (reader["ContactTypeId"] != DBNull.Value)
                {
                    _businessEntityContact.ContactTypeId = Convert.ToInt32(reader["ContactTypeId"]);
                }
                if (reader["RowGuid"] != DBNull.Value)
                {
                    _businessEntityContact.RowGuid = new Guid(reader["RowGuid"].ToString());
                }
                if (reader["ModifiedDate"] != DBNull.Value)
                {
                    _businessEntityContact.ModifiedDate = Convert.ToDateTime(reader["ModifiedDate"]);
                }
                if (reader["PersonId"] != DBNull.Value)
                {
                    _businessEntityContact.PersonId = Convert.ToInt32(reader["PersonId"]);
                }
                _businessEntityContact.NewRecord = false;
            }
            reader.Close();
            return(_businessEntityContact);
        }
        public List <BusinessEntityContact> GetAll()
        {
            BusinessEntityContactDAC _businessEntityContactComponent = new BusinessEntityContactDAC();
            IDataReader reader = _businessEntityContactComponent.GetAllBusinessEntityContact().CreateDataReader();
            List <BusinessEntityContact> _businessEntityContactList = new List <BusinessEntityContact>();

            while (reader.Read())
            {
                if (_businessEntityContactList == null)
                {
                    _businessEntityContactList = new List <BusinessEntityContact>();
                }
                BusinessEntityContact _businessEntityContact = new BusinessEntityContact();
                if (reader["ContactTypeId"] != DBNull.Value)
                {
                    _businessEntityContact.ContactTypeId = Convert.ToInt32(reader["ContactTypeId"]);
                }
                if (reader["RowGuid"] != DBNull.Value)
                {
                    _businessEntityContact.RowGuid = new Guid(reader["RowGuid"].ToString());
                }
                if (reader["ModifiedDate"] != DBNull.Value)
                {
                    _businessEntityContact.ModifiedDate = Convert.ToDateTime(reader["ModifiedDate"]);
                }
                if (reader["PersonId"] != DBNull.Value)
                {
                    _businessEntityContact.PersonId = Convert.ToInt32(reader["PersonId"]);
                }
                _businessEntityContact.NewRecord = false;
                _businessEntityContactList.Add(_businessEntityContact);
            }
            reader.Close();
            return(_businessEntityContactList);
        }
        // PUT api/awbuildversion/5
        public void Put(BusinessEntityContact 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.BusinessEntityContactDelete(value);
                if (GetActionType.Value.ToList()[0].Equals("UPDATE"))
                    adventureWorks_BC.BusinessEntityContactUpdate(value);
            }
        }
예제 #6
0
        public virtual BOBusinessEntityContact MapEFToBO(
            BusinessEntityContact ef)
        {
            var bo = new BOBusinessEntityContact();

            bo.SetProperties(
                ef.BusinessEntityID,
                ef.ContactTypeID,
                ef.ModifiedDate,
                ef.PersonID,
                ef.Rowguid);
            return(bo);
        }
예제 #7
0
 public ActionResult Edit([Bind(Include = "BusinessEntityID,PersonID,ContactTypeID,rowguid,ModifiedDate,isDeleted")] BusinessEntityContact businessEntityContact)
 {
     if (ModelState.IsValid)
     {
         db.Entry(businessEntityContact).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.BusinessEntityID = new SelectList(db.BusinessEntities, "BusinessEntityID", "BusinessEntityID", businessEntityContact.BusinessEntityID);
     ViewBag.ContactTypeID    = new SelectList(db.ContactTypes, "ContactTypeID", "Name", businessEntityContact.ContactTypeID);
     ViewBag.PersonID         = new SelectList(db.People, "BusinessEntityID", "PersonType", businessEntityContact.PersonID);
     return(View(businessEntityContact));
 }
예제 #8
0
        public virtual BusinessEntityContact MapBOToEF(
            BOBusinessEntityContact bo)
        {
            BusinessEntityContact efBusinessEntityContact = new BusinessEntityContact();

            efBusinessEntityContact.SetProperties(
                bo.BusinessEntityID,
                bo.ContactTypeID,
                bo.ModifiedDate,
                bo.PersonID,
                bo.Rowguid);
            return(efBusinessEntityContact);
        }
예제 #9
0
        public async Task <IActionResult> Create([Bind("BusinessEntityId,PersonId,ContactTypeId,Rowguid,ModifiedDate")] BusinessEntityContact businessEntityContact)
        {
            if (ModelState.IsValid)
            {
                _context.Add(businessEntityContact);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BusinessEntityId"] = new SelectList(_context.BusinessEntity, "BusinessEntityId", "BusinessEntityId", businessEntityContact.BusinessEntityId);
            ViewData["ContactTypeId"]    = new SelectList(_context.ContactType, "ContactTypeId", "Name", businessEntityContact.ContactTypeId);
            ViewData["PersonId"]         = new SelectList(_context.Person, "BusinessEntityId", "FirstName", businessEntityContact.PersonId);
            return(View(businessEntityContact));
        }
예제 #10
0
 public bool BusinessEntityContactDelete(BusinessEntityContact businessentitycontact)
 {
     return(Execute <bool>(dal =>
     {
         BusinessEntityContact businessentitycontactDelete = dal.BusinessEntityContact.Where(x => x.BusinessEntityID == businessentitycontact.BusinessEntityID).FirstOrDefault();
         if (businessentitycontactDelete != null)
         {
             dal.BusinessEntityContact.DeleteOnSubmit(businessentitycontactDelete);
             dal.SubmitChanges();
             return true;
         }
         return false;
     }));
 }
        // DELETE: odata/BusinessEntityContacts(5)
        public IHttpActionResult Delete([FromODataUri] int key)
        {
            BusinessEntityContact businessEntityContact = _db.BusinessEntityContacts.Find(key);

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

            _db.BusinessEntityContacts.Remove(businessEntityContact);
            _db.SaveChanges();

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public void MapEFToBOList()
        {
            var mapper = new DALBusinessEntityContactMapper();
            BusinessEntityContact entity = new BusinessEntityContact();

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

            List <BOBusinessEntityContact> response = mapper.MapEFToBO(new List <BusinessEntityContact>()
            {
                entity
            });

            response.Count.Should().Be(1);
        }
예제 #13
0
        // GET: BusinessEntityContacts/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BusinessEntityContact businessEntityContact = db.BusinessEntityContacts.Find(id);

            if (businessEntityContact == null)
            {
                return(HttpNotFound());
            }
            return(View(businessEntityContact));
        }
        public StoreContacts Populate(SqlDataReader reader)
        {
            ContactType contactType = new ContactType
            {
                Name = reader["ContactType"].ToString(),
            };

            BusinessEntityContact businessEntityContact = new BusinessEntityContact
            {
                PersonID      = Convert.ToInt32((int)reader["BusinessEntityID"]),
                ContactTypeID = Convert.ToInt32((int)reader["BusinessEntityID"]),
                ContactType   = contactType
            };

            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
            };

            return(new StoreContacts
            {
                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,
                BusinessEntityContact = businessEntityContact
            });
        }
        public void MapEFToBO()
        {
            var mapper = new DALBusinessEntityContactMapper();
            BusinessEntityContact entity = new BusinessEntityContact();

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

            BOBusinessEntityContact response = mapper.MapEFToBO(entity);

            response.BusinessEntityID.Should().Be(1);
            response.ContactTypeID.Should().Be(1);
            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.PersonID.Should().Be(1);
            response.Rowguid.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"));
        }
        // PUT api/awbuildversion/5
        public void Put(BusinessEntityContact 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.BusinessEntityContactDelete(value);
                }
                if (GetActionType.Value.ToList()[0].Equals("UPDATE"))
                {
                    adventureWorks_BC.BusinessEntityContactUpdate(value);
                }
            }
        }
예제 #17
0
        public async void Get()
        {
            var mock   = new ServiceMockFacade <IBusinessEntityContactRepository>();
            var record = new BusinessEntityContact();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(record));
            var service = new BusinessEntityContactService(mock.LoggerMock.Object,
                                                           mock.RepositoryMock.Object,
                                                           mock.ModelValidatorMockFactory.BusinessEntityContactModelValidatorMock.Object,
                                                           mock.BOLMapperMockFactory.BOLBusinessEntityContactMapperMock,
                                                           mock.DALMapperMockFactory.DALBusinessEntityContactMapperMock);

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

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
예제 #18
0
        // GET: BusinessEntityContacts/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BusinessEntityContact businessEntityContact = db.BusinessEntityContacts.Find(id);

            if (businessEntityContact == null)
            {
                return(HttpNotFound());
            }
            ViewBag.BusinessEntityID = new SelectList(db.BusinessEntities, "BusinessEntityID", "BusinessEntityID", businessEntityContact.BusinessEntityID);
            ViewBag.ContactTypeID    = new SelectList(db.ContactTypes, "ContactTypeID", "Name", businessEntityContact.ContactTypeID);
            ViewBag.PersonID         = new SelectList(db.People, "BusinessEntityID", "PersonType", businessEntityContact.PersonID);
            return(View(businessEntityContact));
        }
        public async Task CreateContact(ContactDomainObj contactDomainObj)
        {
            await DoDatabaseValidation(contactDomainObj);

            var strategy = DbContext.Database.CreateExecutionStrategy();
            await strategy.ExecuteAsync(async() =>
            {
                using (var transaction = DbContext.Database.BeginTransaction())
                {
                    var bizEntity = new BusinessEntity {
                    };
                    DbContext.BusinessEntity.Add(bizEntity);
                    await Save();

                    contactDomainObj.BusinessEntityID = bizEntity.BusinessEntityID;
                    var contact = new AdventureWorks.Models.Person.Person {
                    };
                    contact.Map(contactDomainObj);

                    contact.EmailAddressObj = new EmailAddress
                    {
                        BusinessEntityID   = bizEntity.BusinessEntityID,
                        PersonEmailAddress = contactDomainObj.EmailAddress
                    };

                    contact.PasswordObj = new PersonPWord
                    {
                        PasswordHash = contactDomainObj.EmailPasswordHash,
                        PasswordSalt = contactDomainObj.EmailPasswordSalt
                    };

                    DbContext.Person.Add(contact);
                    await Save();

                    var bec = new BusinessEntityContact
                    {
                        BusinessEntityID = contactDomainObj.ParentEntityID,
                        PersonID         = contact.BusinessEntityID,
                        ContactTypeID    = contactDomainObj.ContactTypeID
                    };
                    DbContext.BusinessEntityContact.Add(bec);
                    await Save();
                    transaction.Commit();
                }
            });
        }
예제 #20
0
        public bool BusinessEntityContactUpdate(BusinessEntityContact businessentitycontact)
        {
            return(Execute <bool>(dal =>
            {
                BusinessEntityContact businessentitycontactUpdate = dal.BusinessEntityContact.Where(x => x.BusinessEntityID == businessentitycontact.BusinessEntityID).FirstOrDefault();
                if (businessentitycontactUpdate != null)
                {
                    businessentitycontactUpdate.BusinessEntityID = businessentitycontact.BusinessEntityID;
                    businessentitycontactUpdate.PersonID = businessentitycontact.PersonID;
                    businessentitycontactUpdate.ContactTypeID = businessentitycontact.ContactTypeID;
                    businessentitycontactUpdate.rowguid = businessentitycontact.rowguid;
                    businessentitycontactUpdate.ModifiedDate = businessentitycontact.ModifiedDate;

                    dal.SubmitChanges();
                    return true;
                }
                return false;
            }));
        }
예제 #21
0
        public ActionResult DeleteConfirmed(int id)
        {
            var res = (from c in db.BusinessEntityContacts
                       where c.BusinessEntityID == id
                       select c).FirstOrDefault();

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

            BusinessEntityContact businessEntity = db.BusinessEntityContacts.Find(id);



            return(View(businessEntity));
        }
        // PUT: odata/BusinessEntityContacts(5)
        public IHttpActionResult Put([FromODataUri] int key, Delta <BusinessEntityContact> patch)
        {
            Validate(patch.GetInstance());

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

            BusinessEntityContact businessEntityContact = _db.BusinessEntityContacts.Find(key);

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

            patch.Put(businessEntityContact);

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

            return(Updated(businessEntityContact));
        }
        private static void AddAddressesAndContactsToVendor(AdventureWorksContext ctx)
        {
            if (ctx.Vendor.Any())
            {
                var vendorAddresses = SampleData.GetVendorAddresses();

                // AUSTRALI0001
                var vendor = ctx.Vendor.AsNoTracking()
                             .Where(v => v.AccountNumber == "AUSTRALI0001")
                             .Select(c => new { ID = c.BusinessEntityID })
                             .SingleOrDefault();

                var address = vendorAddresses.First(a => a.AddressLine1 == "28 San Marino Ct" && a.City == "Bellingham");
                if (address != null)
                {
                    address.BusinessEntityAddressObj.BusinessEntityID = vendor.ID;
                    ctx.Address.Add(address);
                }

                var contact1 = ctx.Person.AsNoTracking()
                               .Where(c => c.FirstName == "Paula" && c.MiddleName == "B." && c.LastName == "Moberly")
                               .Select(c => new { ID = c.BusinessEntityID })
                               .SingleOrDefault();
                var contact2 = ctx.Person.AsNoTracking()
                               .Where(c => c.FirstName == "Charlene" && c.MiddleName == "J." && c.LastName == "Wojcik")
                               .Select(c => new { ID = c.BusinessEntityID })
                               .SingleOrDefault();
                var contact3 = ctx.Person.AsNoTracking()
                               .Where(c => c.FirstName == "Jo" && c.MiddleName == "J." && c.LastName == "Zimmerman")
                               .Select(c => new { ID = c.BusinessEntityID })
                               .SingleOrDefault();

                var bc1 = new BusinessEntityContact {
                    BusinessEntityID = vendor.ID, PersonID = contact1.ID, ContactTypeID = 18
                };
                var bc2 = new BusinessEntityContact {
                    BusinessEntityID = vendor.ID, PersonID = contact2.ID, ContactTypeID = 19
                };
                var bc3 = new BusinessEntityContact {
                    BusinessEntityID = vendor.ID, PersonID = contact3.ID, ContactTypeID = 17
                };
                ctx.BusinessEntityContact.AddRange(new List <BusinessEntityContact> {
                    bc1, bc2, bc3
                });


                // TRIKES0001
                vendor = ctx.Vendor.AsNoTracking()
                         .Where(v => v.AccountNumber == "TRIKES0001")
                         .Select(c => new { ID = c.BusinessEntityID })
                         .SingleOrDefault();

                address = vendorAddresses.First(a => a.AddressLine1 == "90 Sunny Ave" && a.City == "Berkeley");
                if (address != null)
                {
                    address.BusinessEntityAddressObj.BusinessEntityID = vendor.ID;
                    ctx.Address.Add(address);
                }

                var contact4 = ctx.Person.AsNoTracking()
                               .Where(c => c.FirstName == "William" && c.MiddleName == "J." && c.LastName == "Monroe")
                               .Select(c => new { ID = c.BusinessEntityID })
                               .SingleOrDefault();

                var bc4 = new BusinessEntityContact {
                    BusinessEntityID = vendor.ID, PersonID = contact4.ID, ContactTypeID = 18
                };
                ctx.BusinessEntityContact.Add(bc4);


                // LIGHTSP0001
                vendor = ctx.Vendor.AsNoTracking()
                         .Where(v => v.AccountNumber == "LIGHTSP0001")
                         .Select(c => new { ID = c.BusinessEntityID })
                         .SingleOrDefault();

                address = vendorAddresses.First(a => a.AddressLine1 == "298 Sunnybrook Drive" && a.City == "Spring Valley");
                if (address != null)
                {
                    address.BusinessEntityAddressObj.BusinessEntityID = vendor.ID;
                    ctx.Address.Add(address);
                }

                var contact5 = ctx.Person.AsNoTracking()
                               .Where(c => c.FirstName == "Marie" && c.MiddleName == "E." && c.LastName == "Moya")
                               .Select(c => new { ID = c.BusinessEntityID })
                               .SingleOrDefault();

                var bc5 = new BusinessEntityContact {
                    BusinessEntityID = vendor.ID, PersonID = contact5.ID, ContactTypeID = 17
                };
                ctx.BusinessEntityContact.Add(bc5);

                // DFWBIRE0001
                var dfwVendor = ctx.Vendor.AsNoTracking()
                                .Where(v => v.AccountNumber == "DFWBIRE0001")
                                .Select(c => new { ID = c.BusinessEntityID })
                                .SingleOrDefault();

                var terriPhide = ctx.Person.AsNoTracking()
                                 .Where(c => c.FirstName == "Terri" && c.LastName == "Phide")
                                 .Select(c => new { ID = c.BusinessEntityID })
                                 .SingleOrDefault();

                var bc6 = new BusinessEntityContact {
                    BusinessEntityID = dfwVendor.ID, PersonID = terriPhide.ID, ContactTypeID = 17
                };
                ctx.BusinessEntityContact.Add(bc6);


                // DESOTOB0001
                var desotoVendor = ctx.Vendor.AsNoTracking()
                                   .Where(v => v.AccountNumber == "DESOTOB0001")
                                   .Select(c => new { ID = c.BusinessEntityID })
                                   .SingleOrDefault();

                var address1 = vendorAddresses.First(a => a.AddressLine1 == "1900 Desoto Court" && a.City == "Desoto");
                if (address1 != null)
                {
                    address1.BusinessEntityAddressObj.BusinessEntityID = desotoVendor.ID;
                    address1.BusinessEntityAddressObj.AddressTypeID    = 3;
                    ctx.Address.Add(address1);
                }

                var address2 = vendorAddresses.FirstOrDefault(a => a.AddressLine1 == "211 East Pleasant Run Rd" && a.City == "Desoto");
                if (address2 != null)
                {
                    address2.BusinessEntityAddressObj.BusinessEntityID = desotoVendor.ID;
                    address2.BusinessEntityAddressObj.AddressTypeID    = 7;
                    ctx.Address.Add(address2);
                }

                var johnnyDough = ctx.Person.AsNoTracking()
                                  .Where(c => c.FirstName == "Johnny" && c.LastName == "Dough")
                                  .Select(c => new { ID = c.BusinessEntityID })
                                  .SingleOrDefault();

                var bc7 = new BusinessEntityContact {
                    BusinessEntityID = desotoVendor.ID, PersonID = johnnyDough.ID, ContactTypeID = 17
                };
                ctx.BusinessEntityContact.Add(bc7);


                // CYCLERU0001
                var rusVendor = ctx.Vendor.AsNoTracking()
                                .Where(v => v.AccountNumber == "CYCLERU0001")
                                .Select(c => new { ID = c.BusinessEntityID })
                                .SingleOrDefault();

                address = vendorAddresses.FirstOrDefault(a => a.AddressLine1 == "6266 Melody Lane" && a.City == "Dallas");
                if (address != null)
                {
                    address.BusinessEntityAddressObj.BusinessEntityID = rusVendor.ID;
                    address.BusinessEntityAddressObj.AddressTypeID    = 3;
                    ctx.Address.Add(address);
                }


                ctx.SaveChanges();
            }
        }
        public void ShouldAddVendorAndContactThenLinkContactToVendor()
        {
            SampleDataInitialization.InitializeData(ctx);
            ExecuteInATransaction(RunTheTest);

            void RunTheTest()
            {
                // Create the vendor
                var vendorEntity = new BusinessEntity
                {
                    VendorObj = new Vendor
                    {
                        AccountNumber   = "OAKCLIFF0001",
                        Name            = "Oak Cliff Bike Resellers",
                        CreditRating    = CreditRating.Superior,
                        PreferredVendor = true,
                        IsActive        = true
                    }
                };

                // Create the vendor point of contact with phone, email, and email password
                var contactEntity = new BusinessEntity
                {
                    PersonObj = new AdventureWorks.Models.Person.Person
                    {
                        PersonType         = "VC",
                        IsEasternNameStyle = false,
                        Title           = "Big Pimp",
                        FirstName       = "Terri",
                        MiddleName      = "J",
                        LastName        = "Phide",
                        Suffix          = "Mr.",
                        EmailPromotion  = EmailPromoPreference.NoPromotions,
                        EmailAddressObj = new EmailAddress
                        {
                            PersonEmailAddress = "*****@*****.**"
                        },
                        PasswordObj = new PersonPWord
                        {
                            PasswordHash = "pbFwXWE99vobT6g+vPWFy93NtUU/orrIWafF01hccfM=",
                            PasswordSalt = "bE3XiWw="
                        },
                        Phones =
                        {
                            new PersonPhone {
                                PhoneNumber = "214-555-0142", PhoneNumberTypeID = 1
                            }
                        }
                    }
                };

                // Insert vendor and point of contact into the database
                ctx.BusinessEntity.AddRange(new List <BusinessEntity> {
                    vendorEntity, contactEntity
                });
                ctx.SaveChanges();

                // Create the vendor's address
                var address = new Address
                {
                    AddressLine1             = "123 MLK Blvd",
                    AddressLine2             = "Ste 111",
                    City                     = "Dallas",
                    StateProvinceID          = 73,
                    PostalCode               = "75231",
                    BusinessEntityAddressObj = new BusinessEntityAddress
                    {
                        BusinessEntityID = vendorEntity.BusinessEntityID,
                        AddressTypeID    = 3
                    }
                };

                // Create the link between the vendor's address and the vendor
                var vendorContactLink = new BusinessEntityContact
                {
                    BusinessEntityID = vendorEntity.BusinessEntityID,
                    PersonID         = contactEntity.BusinessEntityID,
                    ContactTypeID    = 17
                };

                // Insert the vendor address and address linking record
                ctx.Address.Add(address);
                ctx.BusinessEntityContact.Add(vendorContactLink);
                ctx.SaveChanges();

                /*
                 *  Adding a vendor and vendor contact results in records being inserted into
                 *  the following eight tables:
                 *      Purchasing.Vendor
                 *      Person.Person
                 *      Person.PersonPhone
                 *      Person.EmailAddress
                 *      Person.Password
                 *      Person.Address
                 *      Person.BusinessEntityAddress
                 *      Person.BusinessEntityContact
                 */
                var vendor = ctx.Vendor
                             .AsNoTracking()
                             .Where(v => v.AccountNumber == "OAKCLIFF0001")
                             .Single <Vendor>();

                var contact = ctx.Person
                              .AsNoTracking()
                              .Where(c => c.FirstName == "Terri" && c.MiddleName == "J" && c.LastName == "Phide")
                              .Single <AdventureWorks.Models.Person.Person>();

                var contactLink = ctx.BusinessEntityContact
                                  .AsNoTracking()
                                  .Where(bec => bec.BusinessEntityID == vendor.BusinessEntityID && bec.PersonID == contact.BusinessEntityID)
                                  .Single <BusinessEntityContact>();

                var addressLink = ctx.BusinessEntityAddress
                                  .AsNoTracking()
                                  .Where(a => a.BusinessEntityID == vendor.BusinessEntityID && a.AddressID == address.AddressID && a.AddressTypeID == 3)
                                  .Single <BusinessEntityAddress>();

                var vendorAddress = ctx.Address
                                    .AsNoTracking()
                                    .Where(a => a.AddressLine1 == "123 MLK Blvd" && a.AddressLine2 == "Ste 111" && a.City == "Dallas" && a.StateProvinceID == 73)
                                    .Single <Address>();

                var vendorContactEmail = ctx.EmailAddress
                                         .AsNoTracking()
                                         .Where(e => e.BusinessEntityID == contactEntity.BusinessEntityID && e.PersonEmailAddress == "*****@*****.**")
                                         .Single <EmailAddress>();

                var vendorContactPhone = ctx.PersonPhone
                                         .AsNoTracking()
                                         .Where(ph => ph.BusinessEntityID == contactEntity.BusinessEntityID && ph.PhoneNumber == "214-555-0142" && ph.PhoneNumberTypeID == 1)
                                         .Single <PersonPhone>();

                var contactPassword = ctx.Password
                                      .AsNoTracking()
                                      .Where(pw => pw.BusinessEntityID == contactEntity.BusinessEntityID && pw.PasswordHash == "pbFwXWE99vobT6g+vPWFy93NtUU/orrIWafF01hccfM=")
                                      .Single <PersonPWord>();

                Assert.NotNull(vendor);
                Assert.NotNull(contact);
                Assert.NotNull(contactLink);
                Assert.NotNull(addressLink);
                Assert.NotNull(vendorAddress);
                Assert.NotNull(vendorContactEmail);
                Assert.NotNull(vendorContactPhone);
                Assert.NotNull(contactPassword);
            }
        }
예제 #25
0
        public bool Insert(BusinessEntityContact businessentitycontact)
        {
            BusinessEntityContactDAC businessentitycontactComponent = new BusinessEntityContactDAC();

            return(businessentitycontactComponent.InsertNewBusinessEntityContact(businessentitycontact.ContactTypeId, businessentitycontact.RowGuid, businessentitycontact.ModifiedDate, businessentitycontact.PersonId));
        }
예제 #26
0
        public bool Update(BusinessEntityContact businessentitycontact, int old_personId)
        {
            BusinessEntityContactDAC businessentitycontactComponent = new BusinessEntityContactDAC();

            return(businessentitycontactComponent.UpdateBusinessEntityContact(businessentitycontact.ContactTypeId, businessentitycontact.RowGuid, businessentitycontact.ModifiedDate, businessentitycontact.PersonId, old_personId));
        }
 // POST api/awbuildversion
 public void Post(BusinessEntityContact value)
 {
     adventureWorks_BC.BusinessEntityContactAdd(value);
 }
 // POST api/awbuildversion
 public void Post(BusinessEntityContact value)
 {
     adventureWorks_BC.BusinessEntityContactAdd(value);
 }