No Metadata Documentation available.
Inheritance: ObjectContext
コード例 #1
0
        public void Create(CreateCustomerRequest createCustomerRequest)
        {
            using (var context = new PRToolsEntities())
            {
                var customerEntity = new Customer
                                         {

                                             FacebookURL = createCustomerRequest.FacebookUrl,
                                             ZLastName = createCustomerRequest.ZLastName,
                                             ZFirstName = createCustomerRequest.ZFirstName,
                                             WebsiteURL = createCustomerRequest.WebsiteUrl,
                                             TwitterHandle = createCustomerRequest.TwitterHandle,
                                             Phone = createCustomerRequest.Phone,
                                             Name = createCustomerRequest.Name,
                                             ListName = createCustomerRequest.ListName,
                                             GooglePlacesURL = createCustomerRequest.GooglePlacesUrl,
                                         };

                if (createCustomerRequest.ParentCustomerId > 0)
                    customerEntity.ParentCustomerId = createCustomerRequest.ParentCustomerId;

                if (createCustomerRequest.AccountManagerId > 0)
                    customerEntity.AccountManagerId = createCustomerRequest.AccountManagerId;

                if (createCustomerRequest.CustomerType != Domain.CustomerType.Undefined)
                {
                    string customerTypeKey = createCustomerRequest.CustomerType.ToString();
                    CustomerType customerType =
                        context.CustomerTypes.FirstOrDefault(
                            x => x.CustomerTypeKey == customerTypeKey);

                    customerEntity.CustomerType = customerType;
                }

                customerEntity.Addresses.Add(new Address
                                                 {
                                                     Street = createCustomerRequest.MailingAddress.Street,
                                                     AdditionalInfo =
                                                         createCustomerRequest.MailingAddress.AdditionalInfo,
                                                     City = createCustomerRequest.MailingAddress.City,
                                                     State = createCustomerRequest.MailingAddress.State,
                                                     Zipcode = createCustomerRequest.MailingAddress.Zipcode,
                                                     AddressType = "Mailing",
                                                 });

                foreach (Domain.Contact contact in createCustomerRequest.Contacts)
                {
                    customerEntity.Contacts.Add(new Contact
                                                    {
                                                        FirstName = contact.FirstName,
                                                        LastName = contact.LastName,
                                                        Phone = contact.Phone,
                                                        Email = contact.Email,
                                                    });
                }

                context.Customers.AddObject(customerEntity);
                context.SaveChanges();
            }
        }
コード例 #2
0
 protected override void Context()
 {
     var context = new PRToolsEntities();
     _accountRepository = new AccountRepository();
     _expectedAuthorizedActions = new List<string>
                                      {
                                          "CreateAccount",
                                      };
 }
コード例 #3
0
 public bool DeleteById(int id)
 {
     using (var context = new PRToolsEntities())
     {
         var documentToDelete = context.Documents.FirstOrDefault(x => x.DocumentId == id);
         if (documentToDelete == null)
             return false;
         context.DeleteObject(documentToDelete);
         context.SaveChanges();
         return true;
     }
 }
コード例 #4
0
 //todo: need to either use PRG pattern or ajax so don't try to delete multiple times
 public void Delete(DeleteAccountRequest deleteAccountRequest)
 {
     using (var context = new PRToolsEntities())
     {
         Account accountEntity =
             context.Accounts.SingleOrDefault(x => x.AccountId == deleteAccountRequest.AccountId);
         if (accountEntity != null)
         {
             context.Accounts.DeleteObject(accountEntity);
             context.SaveChanges();
         }
     }
 }
コード例 #5
0
        public Domain.CustomerDocumentURL GetCURL(Guid id)
        {
            using (var context = new PRToolsEntities())
            {
                var cdu = context.CustomerDocumentURLs.Where(c => c.CustomerDocumentURLId == id).FirstOrDefault();

                var lx = AutoMapper.Mapper.Map<Data.CustomerDocumentURL, Domain.CustomerDocumentURL>(cdu);
                lx.CustomerName = cdu.Customer.Name;
                lx.CustomerId = cdu.CustomerId ?? 0;
                return lx;
            }
            return null;
        }
コード例 #6
0
        public void ChangePassword(string username, string currentPassword, string newPassword)
        {
            using (var context = new PRToolsEntities())
            {
                IQueryable<Account> result =
                    context.Accounts.Where(x => x.Username == username && x.Password == currentPassword);

                if (result.Count() != 1)
                    throw new ObjectNotFoundException();

                result.First().Password = newPassword;
                result.First().MustChangePassword = false;
                context.SaveChanges();
            }
        }
コード例 #7
0
 public List<Domain.Document> GetAll()
 {
     using (var context = new PRToolsEntities())
     {
         return context.Documents.Select(x => new Domain.Document
                                                  {
                                                      Body = x.Body,
                                                      CreatedByUsername = x.CreatedByUsername,
                                                      CreatedDate = x.CreatedDate,
                                                      DocumentId = x.DocumentId,
                                                      Title = x.Title,
                                                      CustomerId = x.CustomerID ?? 0,
                                                      CustomerName = x.Customer.Name
                                                  }).ToList();
     }
 }
コード例 #8
0
 public void LogException(Exception exception)
 {
     Debug.WriteLine(exception.ToString());
     using (var context = new PRToolsEntities())
     {
         context.AddToLogs(new Log
                               {
                                   LogItemData = exception.Message,
                                   SecondaryLogItemData =
                                       (exception.InnerException != null
                                            ? exception.InnerException.Message
                                            : null),
                                   TertiaryLogItemData = exception.StackTrace,
                               });
         context.SaveChanges();
     }
 }
コード例 #9
0
        public Domain.Document GetById(int id)
        {
            //var document = _context.Documents.Include("DocumentCustomers").FirstOrDefault(x => x.DocumentId == id);
            using (var context = new PRToolsEntities())
            {
                var document = context.Documents.FirstOrDefault(x => x.DocumentId == id);

                return new Domain.Document
                           {
                               Body = document.Body,
                               CreatedByUsername = document.CreatedByUsername,
                               CreatedDate = document.CreatedDate,
                               DocumentId = document.DocumentId,
                               Title = document.Title,
                               CustomerId = document.CustomerID ?? 0,
                               CustomerName = document.Customer.Name
                           };
            }
        }
コード例 #10
0
        public void Create(CreateAccountRequest createAccountRequest, string encryptedPassword)
        {
            using (var context = new PRToolsEntities())
            {
                string roleName = createAccountRequest.Role.ToString();
                Role roleEntity = context.Roles.SingleOrDefault(x => x.RoleName == roleName);
                var accountEntity = new Account
                                        {
                                            FirstName = createAccountRequest.FirstName,
                                            LastName = createAccountRequest.LastName,
                                            Username = createAccountRequest.Username,
                                            Password = encryptedPassword,
                                            Email = createAccountRequest.EmailAddress,
                                            Role = roleEntity,
                                            MustChangePassword = true,
                                        };

                context.Accounts.AddObject(accountEntity);
                context.SaveChanges();
            }
        }
コード例 #11
0
 private CustomerDocumentURL GetCustomerDocumentUrl(int customerid, int documentid, String UserName, PRToolsEntities context)
 {
     var customerDocumentURL = new CustomerDocumentURL
                                       {
                                           CustomerDocumentURLId = Guid.NewGuid(),
                                           CustomerId = customerid,
                                           DocumentId = documentid,
                                           CreatedByUsername = UserName,
                                           CreatedDate = DateTime.Now
                                       };
         context.CustomerDocumentURLs.AddObject(customerDocumentURL);
         return customerDocumentURL;
 }
コード例 #12
0
        public void UpsertLocalizedDocuments(int DocumentId, List<ProcessedDocument> processedDocuments, String userName)
        {
            using (var context = new PRToolsEntities())
            {
                var d = context.Documents.Where(x => x.DocumentId == DocumentId).FirstOrDefault();
                var customerIds = processedDocuments.Select(pd => pd.CustomerId).ToList();

                var existingCustomerURLS = d.CustomerDocumentURLs;

                foreach (var pd in processedDocuments)
                {
                    var durl = existingCustomerURLS.Where(x => x.CustomerId == pd.CustomerId).FirstOrDefault() ??
                               GetCustomerDocumentUrl(pd.CustomerId, DocumentId, userName, context);
                    durl.Title = pd.Title;
                    // may want to not update this if it has been (edited) -- meaning manually tweaked.
                    durl.Body = pd.Body;
                    durl.Edited = pd.Edited;

                    //durl.CustomerId =
                    durl.Status = CustomerDocumentURLStatus.Localized;
                }

                context.SaveChanges();
            }
        }
コード例 #13
0
 public void Update(Domain.CustomerDocumentURL curl)
 {
     using (var context = new PRToolsEntities())
     {
         var cdurl = context.CustomerDocumentURLs.Where(cdu => cdu.CustomerDocumentURLId == curl.URLKey).First();
         cdurl.Title = curl.Title;
         cdurl.Body = curl.Body;
         cdurl.Status = curl.Status;
         cdurl.Edited = curl.Edited;
         cdurl.CustomerComments = curl.CustomerComments;
         context.SaveChanges();
     }
 }
コード例 #14
0
 public DocumentRepository(PRToolsEntities context, ITimeProvider timeProvider)
 {
     _timeProvider = timeProvider;
 }
コード例 #15
0
        public int GetCustomerDocumentCount(int customerId)
        {
            using (var context = new PRToolsEntities())
            {
                IQueryable<CustomerDocumentURL> customerDocumentUrls =
                    context.CustomerDocumentURLs.Where(x => x.CustomerId == customerId);
                IQueryable<Document> documents = context.Documents.Where(x => x.CustomerID == customerId);

                return customerDocumentUrls.Count() + documents.Count();
            }
        }
コード例 #16
0
 public List<Domain.CustomerDocumentURL> GetCustomerDocumentURLs(int DocumentTemplateId)
 {
     using (var context = new PRToolsEntities())
     {
         var d = context.Documents.Where(x => x.DocumentId == DocumentTemplateId).FirstOrDefault();
         return
             d.CustomerDocumentURLs.Select(
                 cdu =>
                 {
                     var lx = AutoMapper.Mapper.Map<Data.CustomerDocumentURL, Domain.CustomerDocumentURL>(cdu);
                     lx.CustomerName = cdu.Customer.Name;
                     lx.CustomerId = cdu.CustomerId ?? 0;
                     return lx;
                 }).ToList();
     }
 }
コード例 #17
0
        public IDictionary<string, string> GetCustomFieldsAndValuesByCustomerId(int customerId)
        {
            using (var context = new PRToolsEntities())
            {
                var returnDictionary = new Dictionary<string, string>();

                var customLocalizationFieldValues = context.CustomLocalizationFieldValues.Include(
                    "CustomLocalizationField").Where(
                        x => x.CustomerId == customerId);

                foreach (var customLocalizationFieldValue in customLocalizationFieldValues)
                {
                    returnDictionary.Add(customLocalizationFieldValue.CustomLocalizationField.FieldName,
                                         customLocalizationFieldValue.FieldValue);
                }

                return returnDictionary;
            }
        }
コード例 #18
0
        public IEnumerable<Domain.Customer> GetByCustomersByIds(IList<int> customerIds)
        {
            using (var context = new PRToolsEntities())
            {
                IQueryable<Customer> custs = context.Customers
                    .Include("Contacts")
                    .Where(c => customerIds.Contains(c.CustomerId));

                return custs.ToList().Select(x => _mappingEngine.Map<Customer, Domain.Customer>(x)).ToList();
            }
        }
コード例 #19
0
        public void Delete(int customerId)
        {
            using (var context = new PRToolsEntities())
            {
                Customer customerEntity =
                    context.Customers.Include("Addresses").FirstOrDefault(x => x.CustomerId == customerId);
                if (customerEntity == null)
                    throw new ObjectNotFoundException();

                List<Address> addressEntities = customerEntity.Addresses.ToList();
                foreach (Address addressEntity in addressEntities)
                {
                    context.DeleteObject(addressEntity);
                }

                List<Contact> contactEntities = customerEntity.Contacts.ToList();
                foreach (Contact contactEntity in contactEntities)
                {
                    context.DeleteObject(contactEntity);
                }

                context.DeleteObject(customerEntity);
                context.SaveChanges();
            }
        }
コード例 #20
0
 public int GetChildrenCount(int customerId)
 {
     using (var context = new PRToolsEntities())
     {
         IQueryable<Customer> children = context.Customers.Where(x => x.ParentCustomerId == customerId);
         return children.Count();
     }
 }
コード例 #21
0
        public void Update(UpdateCustomerRequest updateCustomerRequest)
        {
            using (var context = new PRToolsEntities())
            {
                IQueryable<Customer> customerEntities =
                    context.Customers.Where(x => x.CustomerId == updateCustomerRequest.Id);
                if (customerEntities.Count() < 1)
                    throw new ObjectNotFoundException();

                Customer customerEntity = customerEntities.FirstOrDefault();
                customerEntity.Name = updateCustomerRequest.Name;
                customerEntity.Phone = updateCustomerRequest.Phone;
                customerEntity.GooglePlacesURL = updateCustomerRequest.GooglePlacesUrl;
                customerEntity.TwitterHandle = updateCustomerRequest.TwitterHandle;
                customerEntity.WebsiteURL = updateCustomerRequest.WebsiteUrl;
                customerEntity.FacebookURL = updateCustomerRequest.FacebookUrl;
                customerEntity.ZFirstName = updateCustomerRequest.ZFirstName;
                customerEntity.ZLastName = updateCustomerRequest.ZLastName;

                if (updateCustomerRequest.ParentCustomerId > 0)
                    customerEntity.ParentCustomerId = updateCustomerRequest.ParentCustomerId;
                else
                {
                    customerEntity.ParentCustomerId = null;
                }

                if(updateCustomerRequest.AccountManagerId > 0)
                    customerEntity.AccountManagerId = updateCustomerRequest.AccountManagerId;
                else
                {
                    customerEntity.AccountManagerId = null;
                }

                if (updateCustomerRequest.CustomerType != Domain.CustomerType.Undefined)
                {
                    string customerTypeKey = updateCustomerRequest.CustomerType.ToString();
                    CustomerType customerType =
                        context.CustomerTypes.FirstOrDefault(x => x.CustomerTypeKey == customerTypeKey);
                    customerEntity.CustomerType = customerType;
                }

                Address addressEntity = context.Addresses.FirstOrDefault();
                addressEntity.Street = updateCustomerRequest.MailingAddress.Street;
                addressEntity.AdditionalInfo = updateCustomerRequest.MailingAddress.AdditionalInfo;
                addressEntity.City = updateCustomerRequest.MailingAddress.City;
                addressEntity.State = updateCustomerRequest.MailingAddress.State;
                addressEntity.Zipcode = updateCustomerRequest.MailingAddress.Zipcode;

                foreach (Domain.Contact contact in updateCustomerRequest.Contacts)
                {
                    int id = contact.Id;
                    Contact contactEntity = context.Contacts.FirstOrDefault(x => x.ContactId == id);

                    contactEntity.FirstName = contact.FirstName;
                    contactEntity.LastName = contact.LastName;
                    contactEntity.Phone = contact.Phone;
                    contactEntity.Email = contact.Email;
                }

                context.SaveChanges();
            }
        }
コード例 #22
0
        public IEnumerable<Domain.Customer> QuickSearch(string searchString)
        {
            using (var context = new PRToolsEntities())
            {
                string[] searchWords = searchString.Split(' ');

                IEnumerable<IQueryable<Customer>> customerEntityLists =
                    searchWords.Select(
                        x => (from customerLists in context.Customers.Include("Contacts").Include("Addresses")
                              where customerLists.Name.Contains(x)
                              select customerLists));

                IEnumerable<Customer> customerEntities = (from customers in customerEntityLists
                                                          from customer in customers
                                                          select customer);

                var domainCustomers = new List<Domain.Customer>();
                foreach (Customer customerEntity in customerEntities)
                {
                    var customer = new Domain.Customer
                                       {
                                           CustomerId = customerEntity.CustomerId,
                                           Name = customerEntity.Name,
                                           CustomerType =
                                               (customerEntity.CustomerTypeKey != null
                                                    ? (Domain.CustomerType)
                                                      Enum.Parse(typeof (Domain.CustomerType),
                                                                 customerEntity.CustomerTypeKey)
                                                    : Domain.CustomerType.Undefined),
                                           ParentCustomerId = customerEntity.ParentCustomerId ?? 0
                                       };
                    if (customer.ParentCustomerId != 0)
                    {
                        customer.ParentName = customerEntity.Customer1.Name;
                    }
                    else
                    {
                        customer.ParentName = customer.Name;
                    }

                    Address mailingAddress = customerEntity.Addresses.FirstOrDefault(x => x.AddressType == "Mailing");
                    if (mailingAddress != null)
                    {
                        customer.MailingAddress = new Domain.Address
                                                      {
                                                          Street = mailingAddress.Street,
                                                          AdditionalInfo = mailingAddress.AdditionalInfo,
                                                          City = mailingAddress.City,
                                                          State = mailingAddress.State,
                                                          Zipcode = mailingAddress.Zipcode,
                                                      };
                    }

                    foreach (Contact contact in customerEntity.Contacts)
                    {
                        customer.AddContact(new Domain.Contact
                                                {
                                                    FirstName = contact.FirstName,
                                                    LastName = contact.LastName,
                                                    Phone = contact.Phone,
                                                });
                    }
                    domainCustomers.Add(customer);
                }
                return domainCustomers;
            }
        }
コード例 #23
0
 public bool NameExists(string name)
 {
     using (var context = new PRToolsEntities())
     {
         return context.Customers.Where(x => x.Name == name).Count() > 0;
     }
 }
コード例 #24
0
 public IEnumerable<Domain.Customer> GetAllShallow()
 {
     using (var context = new PRToolsEntities())
     {
         return context.Customers.Select(x => new Domain.Customer
                                                  {
                                                      CustomerId = x.CustomerId,
                                                      Name = x.Name,
                                                  }).ToList();
     }
 }
コード例 #25
0
        public Domain.Customer Get(int customerId)
        {
            using (var context = new PRToolsEntities())
            {
                Customer customerEntity = context.Customers.Include("Addresses").Include("Contacts")
                    .FirstOrDefault(x => x.CustomerId == customerId);
                Domain.Customer customer = _mappingEngine.Map<Customer, Domain.Customer>(customerEntity);

                foreach (Contact contactEntity in customerEntity.Contacts)
                {
                    var contact = new Domain.Contact
                                      {
                                          Id = contactEntity.ContactId,
                                          FirstName = contactEntity.FirstName,
                                          LastName = contactEntity.LastName,
                                          Phone = contactEntity.Phone,
                                          Email = contactEntity.Email,

                                      };
                    customer.AddContact(contact);
                }

                return customer;
            }
        }
コード例 #26
0
        public Domain.Document Save(string username, SaveDocumentInputModel saveDocumentInputModel)
        {
            using (var context = new PRToolsEntities())
            {
                var documentEntity = new Document
                                         {
                                             CreatedByUsername = username,
                                             Title = saveDocumentInputModel.Title,
                                             Body = saveDocumentInputModel.Body,
                                             CreatedDate = _timeProvider.Now,
                                             CustomerID = saveDocumentInputModel.CustomerId
                                         };
                context.Documents.AddObject(documentEntity);
                context.SaveChanges();

                return new Domain.Document
                           {
                               DocumentId = documentEntity.DocumentId,
                               Title = documentEntity.Title,
                               Body = documentEntity.Body,
                               CreatedByUsername = documentEntity.CreatedByUsername,
                               CreatedDate = documentEntity.CreatedDate,
                           };
            }
        }
コード例 #27
0
        public Domain.Document Save(string username, Domain.Document document)
        {
            using (var context = new PRToolsEntities())
            {
                var documentEntity = new Document
                {
                    CreatedByUsername = username,
                    Title = document.Title,
                    Body = document.Body,
                    CreatedDate = _timeProvider.Now,
                    CustomerID = document.CustomerId,
                    CutoffDate = document.CutoffDate,
                };
                context.Documents.AddObject(documentEntity);
                context.SaveChanges();

                return new Domain.Document
                {
                    DocumentId = documentEntity.DocumentId,
                    Title = documentEntity.Title,
                    Body = documentEntity.Body,
                    CreatedByUsername = documentEntity.CreatedByUsername,
                    CreatedDate = documentEntity.CreatedDate,
                    CustomerId = Convert.ToInt32(documentEntity.CustomerID),
                    CutoffDate = Convert.ToDateTime(documentEntity.CutoffDate),
                };
            }
        }
コード例 #28
0
        public Domain.Document Update(string username, Domain.Document document)
        {
            using (var context = new PRToolsEntities())
            {
                Document currentDocument =
                    context.Documents.FirstOrDefault(x => x.DocumentId == document.DocumentId);

                currentDocument.Title = document.Title;
                currentDocument.Body = document.Body;
                currentDocument.CustomerID = document.CustomerId;
                context.SaveChanges();

                return new Domain.Document
                           {
                               Body = currentDocument.Body,
                               CreatedByUsername = currentDocument.CreatedByUsername,
                               CreatedDate = currentDocument.CreatedDate,
                               DocumentId = currentDocument.DocumentId,
                               Title = currentDocument.Title,
                               CustomerId = Convert.ToInt32(currentDocument.CustomerID),
                           };
            }
        }
コード例 #29
0
 protected override void Context()
 {
     var context = new PRToolsEntities();
     _logger = new SqlServerLogger();
 }
コード例 #30
0
        public IEnumerable<Domain.Customer> GetChildrenCustomers(int parentCustomerId)
        {
            using (var context = new PRToolsEntities())
            {
                IQueryable<Customer> customers = context.Customers
                    .Include("Contacts")
                    .Where(c => c.ParentCustomerId == parentCustomerId);

                var domainCustomers = new List<Domain.Customer>();
                foreach (Customer customer in customers)
                {
                    Domain.Customer domainCustomer = _mappingEngine.Map<Customer, Domain.Customer>(customer);
                    foreach (Contact contact in customer.Contacts)
                    {
                        domainCustomer.AddContact(_mappingEngine.Map<Contact, Domain.Contact>(contact));
                    }
                    domainCustomers.Add(domainCustomer);
                }
                return domainCustomers.ToList();
            }
        }