protected override void CommandBody(UMSEntities context) { User user = context.Users.FirstOrDefault <User>((User u) => u.UserId == this._userId); if (user != null) { user.HasNotifications = this._notifications; } }
protected override void CommandBody(UMSEntities context) { List <BrandType> brandTypes = new List <BrandType>(); foreach (Brand brand in (IEnumerable <Brand>)context.Brands) { brandTypes.Add(new BrandType(brand.BrandId, brand.Description)); } this.CommandResult = brandTypes; }
protected override void CommandBody(UMSEntities context) { User user = context.Users.Include("Emails").Include("Emails.EmailType").Include("UserToBooks").Include("UserToBooks.Book").Include("UserToBooks.Book.Brand").Include("Phones").Include("Phones.PhoneType").Include("Addresses").SingleOrDefault <User>((User a) => a.UserId == this._userId); if (user == null) { throw new Exception("Selected null account form DB"); } Account account = new Account() { Id = user.UserId, PrimaryEmail = user.PrimaryEmail, FirstName = user.FirstName, LastName = user.LastName }; account.CommunicationSettings.HasLeads = user.HasLeadsNotifications; account.CommunicationSettings.HasNotifications = user.HasNotifications; account.CreateUserId = user.CreateUserId; account.CreateDate = user.CreateDate; account.ModifyUserId = user.ModifyUserId; account.ModifyDate = user.ModifyDate; account.Phones = ( from dbPhone in user.Phones select new UserManagementSystem.Entities.Phone(dbPhone.PhoneId, new UserManagementSystem.Entities.PhoneType(dbPhone.PhoneTypeReference.Value.PhoneTypeId, dbPhone.PhoneType.Description), dbPhone.Phone1, dbPhone.CreateDate, dbPhone.ModifyDate, dbPhone.CreateUserId, dbPhone.ModifyUserId)).ToList <UserManagementSystem.Entities.Phone>(); account.Emails = ( from dbEmail in user.Emails select new UserManagementSystem.Entities.Email(dbEmail.EmailId, new UserManagementSystem.Entities.EmailType(dbEmail.EmailTypeReference.Value.EmailTypeId, dbEmail.EmailType.Description), dbEmail.Email1, dbEmail.CreateDate, dbEmail.ModifyDate, dbEmail.CreateUserId, dbEmail.ModifyUserId)).ToList <UserManagementSystem.Entities.Email>(); account.Publications = new List <Publication>(); foreach (UserToBook userToBook in user.UserToBooks) { Publication publication = new Publication(userToBook.Book.BookId, userToBook.Book.BookNumber, new BrandType(userToBook.Book.Brand.BrandId, userToBook.Book.Brand.Description)); account.Publications.Add(publication); } account.FullAddresses = new List <FullAddress>(); Address address = user.Addresses.FirstOrDefault <Address>(); if (address != null) { UserManagementSystem.DAL.Country country = address.City.State.Country; UserManagementSystem.Entities.Country country1 = new UserManagementSystem.Entities.Country(country.CountryId, country.Code, country.Name); UserManagementSystem.DAL.State state = address.City.State; UserManagementSystem.Entities.State state1 = new UserManagementSystem.Entities.State(state.StateId, state.Code, state.Name, country1); UserManagementSystem.DAL.City city = address.City; UserManagementSystem.Entities.City city1 = new UserManagementSystem.Entities.City(city.CityId, city.Name, state1); FullAddress fullAddress = new FullAddress(address.AddressId, address.AddressLine1, address.AddressLine2, city1, state1, country1, address.PostalCode, address.CreateUserId, user.ModifyUserId, user.CreateDate, address.ModifyDate); account.FullAddresses.Add(fullAddress); } this.CommandResult = account; }
protected override void CommandBody(UMSEntities context) { List <UserManagementSystem.Entities.EmailType> emailTypes = new List <UserManagementSystem.Entities.EmailType>(); foreach (UserManagementSystem.DAL.EmailType emailType in (IEnumerable <UserManagementSystem.DAL.EmailType>)context.EmailTypes) { UserManagementSystem.Entities.EmailType emailType1 = new UserManagementSystem.Entities.EmailType() { Id = emailType.EmailTypeId, Description = emailType.Description }; emailTypes.Add(emailType1); } this.CommandResult = emailTypes; }
protected override void CommandBody(UMSEntities context) { List <Publication> publications = new List <Publication>(); List <Book> list = ( from b in context.Books.Include("Brand") where b.BrandId == this._brandTypeId select b).ToList <Book>(); foreach (Book book in list) { Publication publication = new Publication(book.BookId, book.BookNumber, new BrandType(book.Brand.BrandId, book.Brand.Description)); publications.Add(publication); } this.CommandResult = publications; }
protected override void CommandBody(UMSEntities context) { User user = context.Users.SingleOrDefault <User>((User u) => u.UserId == this._userId); if (user != null) { IQueryable <Phone> phones = from p in context.Phones where p.UserId == this._userId select p; foreach (Phone phone in phones) { context.DeleteObject(phone); } IQueryable <Email> emails = from p in context.Emails where p.UserId == this._userId select p; foreach (Email email in emails) { context.DeleteObject(email); } IQueryable <Address> addresses = from p in context.Addresses where p.UserId == this._userId select p; foreach (Address address in addresses) { context.DeleteObject(address); } IQueryable <UserToBook> userToBooks = from p in context.UserToBooks where p.UserId == this._userId select p; foreach (UserToBook userToBook in userToBooks) { context.DeleteObject(userToBook); } context.DeleteObject(user); this.CommandResult = 1; } else { this.CommandResult = 0; } }
protected override void CommandBody(UMSEntities context) { List <UserManagementSystem.DAL.Country> list = context.Countries.ToList <UserManagementSystem.DAL.Country>(); List <UserManagementSystem.Entities.Country> countries = new List <UserManagementSystem.Entities.Country>(); foreach (UserManagementSystem.DAL.Country country in list) { UserManagementSystem.Entities.Country country1 = new UserManagementSystem.Entities.Country() { Id = country.CountryId, Name = country.Name, Code = country.Code }; countries.Add(country1); } this.CommandResult = countries; }
protected override void CommandBody(UMSEntities context) { List <UserManagementSystem.DAL.City> list = ( from s in context.Cities where s.StateId == this._stateId select s).ToList <UserManagementSystem.DAL.City>(); List <UserManagementSystem.Entities.City> cities = new List <UserManagementSystem.Entities.City>(); foreach (UserManagementSystem.DAL.City city in list) { UserManagementSystem.Entities.City city1 = new UserManagementSystem.Entities.City() { Id = city.CityId, Name = city.Name }; cities.Add(city1); } this.CommandResult = cities; }
protected override void CommandBody(UMSEntities context) { List <UserManagementSystem.DAL.State> states = (this._countryId.HasValue ? ( from s in context.States where (int?)s.CountryId == this._countryId select s).ToList <UserManagementSystem.DAL.State>() : context.States.ToList <UserManagementSystem.DAL.State>()); List <UserManagementSystem.Entities.State> states1 = new List <UserManagementSystem.Entities.State>(); foreach (UserManagementSystem.DAL.State state in states) { UserManagementSystem.Entities.State state1 = new UserManagementSystem.Entities.State() { Id = state.StateId, Name = state.Name, Code = state.Code }; states1.Add(state1); } this.CommandResult = states1; }
protected override void CommandBody(UMSEntities context) { IQueryable <Book> books; List <Publication> publications = new List <Publication>(); if (!this._userId.HasValue) { books = context.Books; } else { books = from u in context.UserToBooks.Include("UserToBooks.Books").Include("UserToBooks.Book.Brand") where (Guid?)u.UserId == this._userId select u into b select b.Book; } foreach (Book book in books) { Publication publication = new Publication(book.BookId, book.BookNumber, new BrandType(book.Brand.BrandId, book.Brand.Description)); publications.Add(publication); } this.CommandResult = publications; }
public virtual void Execute() { try { UMSEntities uMSEntity = new UMSEntities(); try { this.CommandBody(uMSEntity); uMSEntity.SaveChanges(); } finally { if (uMSEntity != null) { ((IDisposable)uMSEntity).Dispose(); } } } catch (Exception exception) { Logger.Error("Error during sql command execution.", exception); throw; } }
protected override void CommandBody(UMSEntities context) { User user = context.Users.SingleOrDefault <User>((User a) => a.UserId == this._userId); if (user == null) { throw new Exception("Selected null account form DB"); } Account account = new Account() { Id = user.UserId, PrimaryEmail = user.PrimaryEmail, FirstName = user.FirstName, LastName = user.LastName }; account.CommunicationSettings.HasLeads = user.HasLeadsNotifications; account.CommunicationSettings.HasNotifications = user.HasNotifications; account.CreateUserId = user.CreateUserId; account.CreateDate = user.CreateDate; account.ModifyUserId = user.ModifyUserId; account.ModifyDate = user.ModifyDate; this.CommandResult = account; }
protected virtual void CommandBody(UMSEntities context) { }
protected override void CommandBody(UMSEntities context) { List <User> list = (this._isAdmin ? context.Users.ToList <User>() : ( from u in context.Users where u.UserToBooks.Any <UserToBook>((UserToBook utb) => utb.UserId == this._userId) select u).ToList <User>()); list.RemoveAll((User u) => u.UserId == this._userId); if (!string.IsNullOrWhiteSpace(this._subnameFilter)) { string lower = this._subnameFilter.Trim().ToLower(); list = ( from u in list where string.Format("{0} {1}", u.FirstName, u.LastName).ToLower().Contains(lower) select u).ToList <User>(); } if (!string.IsNullOrWhiteSpace(this._subEmailFilter)) { string str = this._subEmailFilter.Trim().ToLower(); list = ( from u in list where u.PrimaryEmail.ToLower().Contains(str) select u).ToList <User>(); } if (this._leadFilter != CheckFilter.Any) { list = (this._leadFilter == CheckFilter.Checked ? ( from u in list where u.HasLeadsNotifications select u).ToList <User>() : ( from u in list where !u.HasLeadsNotifications select u).ToList <User>()); } if (this._notificationFilter != CheckFilter.Any) { list = (this._notificationFilter == CheckFilter.Checked ? ( from u in list where u.HasNotifications select u).ToList <User>() : ( from u in list where !u.HasNotifications select u).ToList <User>()); } this.TotalCount = list.Count <User>(); if (this._nameOrder != SortOrder.Unsorted) { list = (this._nameOrder == SortOrder.Ascending ? ( from u in list orderby string.Format("{0} {1}", u.FirstName, u.LastName) select u).ToList <User>() : ( from u in list orderby string.Format("{0} {1}", u.FirstName, u.LastName) descending select u).ToList <User>()); } if (this._emailOrder != SortOrder.Unsorted) { list = (this._emailOrder == SortOrder.Ascending ? ( from u in list orderby u.PrimaryEmail select u).ToList <User>() : ( from u in list orderby u.PrimaryEmail descending select u).ToList <User>()); } list = list.Skip <User>(this._pageSize * (this._pageIndex - 1)).Take <User>(this._pageSize).ToList <User>(); List <Account> accounts = new List <Account>(); foreach (User user in list) { Account account = new Account() { Id = user.UserId, FirstName = user.FirstName, LastName = user.LastName, PrimaryEmail = user.PrimaryEmail, CommunicationSettings = new CommunicationSettings(user.HasLeadsNotifications, user.HasNotifications), CreateUserId = user.CreateUserId, CreateDate = user.CreateDate, ModifyUserId = user.ModifyUserId, ModifyDate = user.ModifyDate }; accounts.Add(account); } this.CommandResult = accounts; }
protected override void CommandBody(UMSEntities context) { SaveAccountCommand.< > c__DisplayClass28 variable; User firstName = context.Users.FirstOrDefault <User>((User u) => u.UserId == this._account.Id); if (firstName != null) { firstName.FirstName = this._account.FirstName; firstName.LastName = this._account.LastName; firstName.HasNotifications = this._account.CommunicationSettings.HasNotifications; firstName.HasLeadsNotifications = this._account.CommunicationSettings.HasLeads; firstName.ModifyUserId = this._account.ModifyUserId; firstName.ModifyDate = this._account.ModifyDate; IEnumerable <Address> addresses = from addr in context.Addresses where addr.UserId == firstName.UserId select addr; IEnumerable <FullAddress> fullAddresses = this._account.FullAddresses.Where <FullAddress>((FullAddress newAddr) => return addresses.Count <Address>((Address exisAddr) => exisAddr.AddressId == newAddr.Id) == 0); IEnumerable <Address> addresses1 = from exisAddr in addresses where this._account.FullAddresses.Count <FullAddress>((FullAddress newAddr) => newAddr.Id == exisAddr.AddressId) == 0 select exisAddr; IEnumerable <Address> addresses2 = from exisAddr in addresses where this._account.FullAddresses.Count <FullAddress>((FullAddress newAddr) => newAddr.Id == exisAddr.AddressId) > 0 select exisAddr; foreach (FullAddress fullAddress in fullAddresses) { Address address = new Address() { AddressId = fullAddress.Id, AddressLine1 = fullAddress.AddressLine1, AddressLine2 = fullAddress.AddressLine2, CityId = fullAddress.City.Id, PostalCode = fullAddress.Zip, Sequence = 1, CreateUserId = fullAddress.CreateUserId, ModifyUserId = fullAddress.ModifyUserId, CreateDate = fullAddress.CreateDate, ModifyDate = fullAddress.ModifyDate }; context.Addresses.AddObject(address); } foreach (Address id in addresses2) { FullAddress fullAddress1 = this._account.FullAddresses.First <FullAddress>((FullAddress newAddr) => newAddr.Id == id.AddressId); id.AddressId = fullAddress1.Id; id.AddressLine1 = fullAddress1.AddressLine1; id.AddressLine2 = fullAddress1.AddressLine2; id.CityId = fullAddress1.City.Id; id.PostalCode = fullAddress1.Zip; id.Sequence = 1; id.ModifyUserId = fullAddress1.ModifyUserId; id.ModifyDate = fullAddress1.ModifyDate; context.Addresses.Detach(id); context.Addresses.Attach(id); context.ObjectStateManager.ChangeObjectState(id, EntityState.Modified); } addresses1.ToList <Address>().ForEach((Address addr) => context.Addresses.DeleteObject(addr)); IEnumerable <UserManagementSystem.DAL.Phone> phones = from ph in context.Phones where ph.UserId == firstName.UserId select ph; IEnumerable <UserManagementSystem.Entities.Phone> phones1 = this._account.Phones.Where <UserManagementSystem.Entities.Phone>((UserManagementSystem.Entities.Phone newPh) => return phones.Count <UserManagementSystem.DAL.Phone>((UserManagementSystem.DAL.Phone exisPh) => exisPh.PhoneId == newPh.Id) == 0); IEnumerable <UserManagementSystem.DAL.Phone> phones2 = from exisPh in phones where this._account.Phones.Count <UserManagementSystem.Entities.Phone>((UserManagementSystem.Entities.Phone newPh) => newPh.Id == exisPh.PhoneId) == 0 select exisPh; IEnumerable <UserManagementSystem.DAL.Phone> phones3 = from exisPh in phones where this._account.Phones.Count <UserManagementSystem.Entities.Phone>((UserManagementSystem.Entities.Phone newPh) => newPh.Id == exisPh.PhoneId) > 0 select exisPh; foreach (UserManagementSystem.Entities.Phone phone in phones1) { UserManagementSystem.DAL.Phone phone1 = new UserManagementSystem.DAL.Phone() { PhoneId = phone.Id, Phone1 = phone.Number, PhoneTypeId = phone.Type.Id, UserId = this._account.Id, Sequence = 1, CreateUserId = phone.CreateUserId, ModifyUserId = phone.ModifyUserId, CreateDate = phone.CreateDate, ModifyDate = phone.ModifyDate }; context.Phones.AddObject(phone1); } foreach (UserManagementSystem.DAL.Phone number in phones3) { UserManagementSystem.Entities.Phone phone2 = this._account.Phones.First <UserManagementSystem.Entities.Phone>((UserManagementSystem.Entities.Phone newPh) => newPh.Id == number.PhoneId); number.PhoneId = phone2.Id; number.Phone1 = phone2.Number; number.PhoneTypeId = phone2.Type.Id; number.UserId = this._account.Id; number.Sequence = 1; number.ModifyUserId = phone2.ModifyUserId; number.ModifyDate = phone2.ModifyDate; context.Phones.Detach(number); context.Phones.Attach(number); context.ObjectStateManager.ChangeObjectState(number, EntityState.Modified); } phones2.ToList <UserManagementSystem.DAL.Phone>().ForEach((UserManagementSystem.DAL.Phone ph) => context.Phones.DeleteObject(ph)); IEnumerable <UserManagementSystem.DAL.Email> emails = from em in context.Emails where em.UserId == firstName.UserId select em; IEnumerable <UserManagementSystem.Entities.Email> emails1 = this._account.Emails.Where <UserManagementSystem.Entities.Email>((UserManagementSystem.Entities.Email newEm) => return emails.Count <UserManagementSystem.DAL.Email>((UserManagementSystem.DAL.Email exisEm) => exisEm.EmailId == newEm.Id) == 0); IEnumerable <UserManagementSystem.DAL.Email> emails2 = from exisEm in emails where this._account.Emails.Count <UserManagementSystem.Entities.Email>((UserManagementSystem.Entities.Email newEm) => newEm.Id == exisEm.EmailId) == 0 select exisEm; IEnumerable <UserManagementSystem.DAL.Email> emails3 = from exisEm in emails where this._account.Emails.Count <UserManagementSystem.Entities.Email>((UserManagementSystem.Entities.Email newEm) => newEm.Id == exisEm.EmailId) > 0 select exisEm; foreach (UserManagementSystem.Entities.Email email in emails1) { UserManagementSystem.DAL.Email email1 = new UserManagementSystem.DAL.Email() { EmailId = email.Id, Email1 = email.Value, EmailTypeId = email.Type.Id, UserId = this._account.Id, Sequence = 1, CreateUserId = email.CreateUserId, ModifyUserId = email.ModifyUserId, CreateDate = email.CreateDate, ModifyDate = email.ModifyDate }; context.Emails.AddObject(email1); } foreach (UserManagementSystem.DAL.Email value in emails3) { UserManagementSystem.Entities.Email email2 = this._account.Emails.First <UserManagementSystem.Entities.Email>((UserManagementSystem.Entities.Email newEm) => newEm.Id == value.EmailId); value.EmailId = email2.Id; value.Email1 = email2.Value; value.EmailTypeId = email2.Type.Id; value.UserId = this._account.Id; value.Sequence = 1; value.ModifyUserId = email2.ModifyUserId; value.ModifyDate = email2.ModifyDate; context.Emails.Detach(value); context.Emails.Attach(value); context.ObjectStateManager.ChangeObjectState(value, EntityState.Modified); } emails2.ToList <UserManagementSystem.DAL.Email>().ForEach((UserManagementSystem.DAL.Email em) => context.Emails.DeleteObject(em)); IEnumerable <UserToBook> userToBooks = from utb in context.UserToBooks where utb.UserId == this._account.Id select utb; IEnumerable <Publication> publications = this._account.Publications.Where <Publication>((Publication newPublc) => return userToBooks.Count <UserToBook>((UserToBook exisUtb) => exisUtb.BookId == newPublc.Id) == 0); IEnumerable <UserToBook> userToBooks1 = from exisUtb in userToBooks where this._account.Publications.Count <Publication>((Publication publ) => publ.Id == exisUtb.BookId) == 0 select exisUtb; foreach (Publication publication in publications) { UserToBook userToBook = new UserToBook() { BookId = publication.Id, UserId = this._account.Id }; context.UserToBooks.AddObject(userToBook); } userToBooks1.ToList <UserToBook>().ForEach((UserToBook utb) => context.UserToBooks.DeleteObject(utb)); } else { firstName = new User() { UserId = this._account.Id, FirstName = this._account.FirstName, LastName = this._account.LastName, PrimaryEmail = this._account.PrimaryEmail, HasNotifications = this._account.CommunicationSettings.HasNotifications, HasLeadsNotifications = this._account.CommunicationSettings.HasLeads, CreateUserId = this._account.CreateUserId, CreateDate = this._account.CreateDate, ModifyUserId = this._account.ModifyUserId, ModifyDate = this._account.ModifyDate }; foreach (FullAddress fullAddress2 in this._account.FullAddresses) { Address address1 = new Address() { AddressLine1 = fullAddress2.AddressLine1, CityId = fullAddress2.City.Id, UserId = this._account.Id, PostalCode = fullAddress2.Zip, Sequence = 1, CreateUserId = fullAddress2.CreateUserId, CreateDate = fullAddress2.CreateDate, ModifyUserId = fullAddress2.ModifyUserId, ModifyDate = fullAddress2.ModifyDate }; firstName.Addresses.Add(address1); } foreach (Publication publication1 in this._account.Publications) { Book book = context.Books.FirstOrDefault <Book>((Book b) => b.BookId == publication1.Id); if (book != null) { UserToBook userToBook1 = new UserToBook() { BookId = book.BookId, UserId = this._account.Id }; firstName.UserToBooks.Add(userToBook1); } } foreach (UserManagementSystem.Entities.Email email3 in this._account.Emails) { UserManagementSystem.DAL.Email email4 = new UserManagementSystem.DAL.Email() { Email1 = email3.Value, EmailTypeId = email3.Type.Id, UserId = this._account.Id, Sequence = 1, CreateUserId = email3.CreateUserId, CreateDate = email3.CreateDate, ModifyUserId = email3.ModifyUserId, ModifyDate = email3.ModifyDate }; firstName.Emails.Add(email4); } foreach (UserManagementSystem.Entities.Phone phone3 in this._account.Phones) { UserManagementSystem.DAL.Phone phone4 = new UserManagementSystem.DAL.Phone() { Phone1 = phone3.Number, PhoneTypeId = phone3.Type.Id, UserId = this._account.Id, Sequence = 1, CreateUserId = phone3.CreateUserId, CreateDate = phone3.CreateDate, ModifyUserId = phone3.ModifyUserId, ModifyDate = phone3.ModifyDate }; firstName.Phones.Add(phone4); } context.Users.AddObject(firstName); } }
protected override void CommandBody(UMSEntities context) { context.ChangeUserName(this._oldPrimaryEmail, this._newPrimaryEmail); }