public void InsertUserProfile(ExtendedUserProfileContract[] d) { try { lock (MDB) { foreach (var x in d) { var pp = new DB.UserProfile(); x.UserProfile.CopyTo(pp); MDB.UserProfiles.InsertOnSubmit(pp); var mm = new DB.webpages_Membership(); x.WebPagesMembership.CopyTo(mm); pp.webpages_Membership = mm; MDB.webpages_Memberships.InsertOnSubmit(mm); } MDB.SubmitChanges(); } } catch (Exception ex) { HandleMyException(ex); } }
public UserAndProductsContarct[] FindLastUsedProducts(UserProfile2Discriminator u, UserProfileVsLocationDiscriminator pvl) { //TODO: it is not matching how it is implemented in the ProductRepository try { var userRecords = RepositoryFactory.GetUserProfile(); userRecords.Discriminator2 = u; userRecords.UserProfileVsLocationFilter = pvl; var ret = userRecords.OfType <DB.UserProfile>() .Select(p => new UserAndProductsContarct() { UserProfile = p, Products = p.ProfileCredits.OrderByDescending(pc => pc.HasBallance).ThenByDescending(pc => pc.CalculatedTime).ThenByDescending(pc => pc.Product.CreditTransactions.Count).Take(Settings.Default.NumberOfLastProductsToShow) .Select(pc => new ProductCreditContract() { Product = pc.Product, ProfileCredit = pc }).ToArray() }).ToArray(); foreach (var r in ret) { DB.UserProfile profile = (DB.UserProfile)userRecords.Result2.First(z => z.UserId == r.UserProfile.UserId); IQueryable <DB.CreditTransaction> transactions = profile.CreditTransactions.AsQueryable(); if (pvl != null && pvl.Filter != null) { var locations = MDB.UserProfileVsLocations.Where(pvl.Filter); transactions = transactions.Join(locations, location => location.LocationId, transaction => transaction.LocationId, (transaction, location) => transaction ); } var lastTransaction = transactions.LastOrDefault(); if (lastTransaction != null) { var lastPayment = lastTransaction.Payments.LastOrDefault(); if (lastPayment != null) { r.LastPayment = lastPayment; } else { //TODO: replace mocked-up payment with location-settings driven data r.LastPayment = new PaymentImplementor { Amount = lastTransaction.BallanceUnits * lastTransaction.Product.ProductPriceHistories.OrderByDescending(p => p.ChangeDate).First().Price }; } } } return(ret); } catch (Exception ex) { HandleMyException(ex); return(null); } }