public void AddProduct(ProductInfo productInfo, long subdomainid) { // update total products for us UpdateCounters(subdomainid, 1, CounterType.PRODUCTS_MINE); productInfo.p.created = DateTime.UtcNow; productInfo.p.updated = productInfo.p.created; db.products.InsertOnSubmit(productInfo.p); Save("AddProduct"); Debug.Assert(productInfo.p.id != 0); // insert images foreach (var photoUrl in productInfo.photo_urls) { var url = photoUrl; new Thread(() => url.ReadAndSaveProductImageFromUrl(subdomainid, subdomainid, productInfo.p.id)).Start(); } db.SubmitChanges(); #if LUCENE // index product var indexer = new LuceneWorker(db, GetSubDomain(subdomainid).ToIdName()); indexer.AddToIndex(LuceneIndexType.PRODUCTS, productInfo.p); #endif CacheHelper.Instance.invalidate_dependency(DependencyType.products_subdomain, subdomainid.ToString()); }
public void SaveUpdatedTransaction() { // needs an update here to update variant link in orderitem repository.Save(); // save change history var changed = order.ToModel(transactionType, caller_sessionid); var comparer = new CompareObject(); var diff = comparer.Compare(original, changed, currency); if (diff.Count != 0) { repository.AddChangeHistory( caller_sessionid, order.id, transactionType == TransactionType.ORDER ? ChangeHistoryType.ORDERS : ChangeHistoryType.INVOICE, diff ); } repository.UpdateProductsOutOfStock(senderDomain.id); order.lastUpdate = DateTime.UtcNow; repository.Save(); #if LUCENE // index order var indexer = new LuceneWorker(repository, new IdName(senderDomain.id, senderDomain.name)); indexer.AddToIndex(LuceneIndexType.TRANSACTION, order); #endif }
public long AddUser(user u) { db.users.InsertOnSubmit(u); db.SubmitChanges(); #if LUCENE // index for search var indexer = new LuceneWorker(db, u.organisation1.MASTERsubdomain.ToIdName()); indexer.AddToIndex(LuceneIndexType.CONTACTS, u); #endif return(u.id); }
public ActionResult UpdateAddresses(int?[] country, string[] states_canadian, string[] states_other, string[] states_us, string billing_first_name, string billing_last_name, string billing_company, string billing_address, string billing_city, long?billing_citySelected, string billing_postcode, string billing_phone, string shipping_first_name, string shipping_last_name, string shipping_company, string shipping_address, string shipping_city, long?shipping_citySelected, string shipping_postcode, string shipping_phone) { var ownerid = sessionid.Value; var profile = repository.GetUserById(ownerid, subdomainid.Value); if (profile == null) { return(SendJsonErrorResponse("Cannot find profile")); } var addressHandler = new AddressHandler(profile.organisation1, repository); addressHandler.SetShippingAndBillingAddresses(billing_first_name, billing_last_name, billing_company, billing_address, billing_city, billing_citySelected, billing_postcode, billing_phone, country.ElementAtOrDefault(0), states_canadian.ElementAtOrDefault(0), states_other.ElementAtOrDefault(0), states_us.ElementAtOrDefault(0), shipping_first_name, shipping_last_name, shipping_company, shipping_address, shipping_city, shipping_citySelected, shipping_postcode, shipping_phone, country.ElementAtOrDefault(1), states_canadian.ElementAtOrDefault(1), states_other.ElementAtOrDefault(1), states_us.ElementAtOrDefault(1), false); repository.Save(); CacheHelper.Instance.invalidate_dependency(DependencyType.products_subdomain, subdomainid.Value.ToString()); CacheHelper.Instance.invalidate_dependency(DependencyType.organisation, subdomainid.Value.ToString()); #if LUCENE // update index var indexer = new LuceneWorker(db, profile.organisation1.MASTERsubdomain.ToIdName()); indexer.AddToIndex(LuceneIndexType.CONTACTS, profile); #endif return(Json(OPERATION_SUCCESSFUL.ToJsonOKData())); }
public void SaveNewTransaction() { // copy addresses CopyBillingAndShippingAddressesFromReceiverToInvoice(); order.transactions = new transaction(); repository.AddOrder(order); repository.UpdateProductsOutOfStock(senderDomain.id); repository.AddChangeHistory(caller_sessionid, order.id, transactionType == TransactionType.INVOICE ? ChangeHistoryType.INVOICE : ChangeHistoryType.ORDERS, null); repository.UpdateCounters(senderDomain.id, 1, transactionType == TransactionType.INVOICE ? CounterType.INVOICES_SENT : CounterType.ORDERS_SENT); #if LUCENE var indexer = new LuceneWorker(repository, new IdName(senderDomain.id, senderDomain.name)); indexer.AddToIndex(LuceneIndexType.TRANSACTION, order); #endif }
public ActionResult Update(long?id, string email, string address, string city, long?citySelected, string coPhone, string companyName, IEnumerable <int?> country, string fax, string firstName, int?permissions, string gender, string lastName, string notes, string phone, string postcode, string title, string password, IEnumerable <string> states_canadian, IEnumerable <string> states_other, IEnumerable <string> states_us, string billing_first_name, string billing_last_name, string billing_company, string billing_address, string billing_city, long?billing_citySelected, string billing_postcode, string billing_phone, string shipping_first_name, string shipping_last_name, string shipping_company, string shipping_address, string shipping_city, long?shipping_citySelected, string shipping_postcode, string shipping_phone) { if (!id.HasValue) { return(SendJsonErrorResponse("Missing ID")); } try { var contact = repository.GetContact(subdomainid.Value, id.Value); if (contact == null) { return(SendJsonErrorResponse("Missing ID")); } var original = contact.ToModel(sessionid, subdomainid.Value); // no need to take into account whether an organisation is there because it will always be created contact.organisation1.address = address.Trim(); if (citySelected.HasValue) { var mcity = repository.GetCity(citySelected.Value); contact.organisation1.MASTERcity = mcity; } else if (!string.IsNullOrEmpty(city)) { contact.organisation1.MASTERcity = repository.AddCity(city); } if (coPhone != null) { contact.organisation1.phone = coPhone; } if (companyName != null) { contact.organisation1.name = companyName; } if (country != null) { contact.organisation1.country = country.ElementAtOrDefault(0); contact.organisation1.state = AddressHandler.GetState(country.ElementAtOrDefault(0), states_us.ElementAtOrDefault(0), states_canadian.ElementAtOrDefault(0), states_other.ElementAtOrDefault(0)); } if (fax != null) { contact.organisation1.fax = fax; } if (email != null) { contact.email = email; } if (firstName != null) { contact.firstName = firstName; } if (gender != null) { contact.gender = gender; } if (lastName != null) { contact.lastName = lastName; } if (phone != null) { contact.phoneNumber = phone; } if (postcode != null) { contact.organisation1.postcode = postcode; } // handle addresses var addressHandler = new AddressHandler(contact.organisation1, repository); addressHandler.SetShippingAndBillingAddresses(billing_first_name, billing_last_name, billing_company, billing_address, billing_city, billing_citySelected, billing_postcode, billing_phone, country.ElementAtOrDefault(1), states_canadian.ElementAtOrDefault(1), states_other.ElementAtOrDefault(1), states_us.ElementAtOrDefault(1), shipping_first_name, shipping_last_name, shipping_company, shipping_address, shipping_city, shipping_citySelected, shipping_postcode, shipping_phone, country.ElementAtOrDefault(2), states_canadian.ElementAtOrDefault(2), states_other.ElementAtOrDefault(2), states_us.ElementAtOrDefault(2), false); if (title != null) { contact.title = title; } if (!string.IsNullOrEmpty(password)) { // password specified contact.passwordHash = Crypto.Utility.ComputePasswordHash(email + password); } else { // password removed contact.passwordHash = null; } // list of fields that are allowed to be modified if (notes != null) { contact.notes = notes; } // handle permissions if (permissions.HasValue) { contact.permissions = permissions; } repository.AddActivity(sessionid.Value, new ActivityMessage(id.Value, sessionid, ActivityMessageType.CONTACT_UPDATED, new HtmlLink(contact.ToEmailName(true), id.Value).ToContactString()), subdomainid.Value); repository.Save(); #if LUCENE // update search index var indexer = new LuceneWorker(db, MASTERdomain.ToIdName()); indexer.AddToIndex(LuceneIndexType.CONTACTS, contact); #endif // get changed and store in database var changed = contact.ToModel(sessionid, subdomainid.Value); var comparer = new CompareObject(); var diff = comparer.Compare(original, changed); if (diff.Count != 0) { repository.AddChangeHistory(sessionid.Value, contact.id, ChangeHistoryType.CONTACT, diff); } } catch (Exception ex) { return(SendJsonErrorResponse(ex)); } return(Json(id.ToJsonOKData())); }
public ActionResult UpdateProfile(string address, string city, string citySelected, string coPhone, string companyName, int?country, string fax, string firstName, string gender, string lastName, string notes, string phone, string postcode, string title, string currency, string timezone, string email, string states_canadian, string states_other, string states_us) { var ownerid = sessionid.Value; try { var profile = repository.GetUserById(ownerid, subdomainid.Value); if (profile == null) { return(SendJsonErrorResponse("Cannot find profile")); } // no need to take into account whether an organisation is there because it will always be created profile.organisation1.address = address; if (!string.IsNullOrEmpty(citySelected)) { profile.organisation1.city = int.Parse(citySelected); } else if (!string.IsNullOrEmpty(city)) { profile.organisation1.city = repository.AddCity(city).id; } profile.organisation1.phone = coPhone; profile.organisation1.name = companyName; profile.organisation1.fax = fax; if (country != null) { profile.organisation1.country = country; profile.organisation1.state = AddressHandler.GetState(country, states_us, states_canadian, states_other); } profile.firstName = firstName; profile.gender = gender; profile.lastName = lastName; profile.notes = notes; profile.phoneNumber = phone; profile.organisation1.postcode = postcode; profile.title = title; if (!string.IsNullOrEmpty(email) && email != profile.email) { profile.email = email.Trim(); var password = Crypto.Utility.GetRandomString(); // save password hash var hash = Crypto.Utility.ComputePasswordHash(email + password); profile.passwordHash = hash; // set flag profile.settings |= (int)UserSettings.PASSWORD_RESET; // email new password to user var data = new ViewDataDictionary() { { "password", password } }; EmailHelper.SendEmail(EmailViewType.ACCOUNT_PASSWORD_RESET, data, "Password Reset", email, profile.ToFullName(), null); } if (permission.HasFlag(UserPermission.NETWORK_SETTINGS)) { if (!string.IsNullOrEmpty(timezone)) { profile.timezone = timezone; } if (!string.IsNullOrEmpty(currency)) { profile.organisation1.MASTERsubdomain.currency = int.Parse(currency); } } repository.Save(); CacheHelper.Instance.invalidate_dependency(DependencyType.products_subdomain, subdomainid.Value.ToString()); CacheHelper.Instance.invalidate_dependency(DependencyType.organisation, subdomainid.Value.ToString()); #if LUCENE // update index var indexer = new LuceneWorker(db, profile.organisation1.MASTERsubdomain.ToIdName()); indexer.AddToIndex(LuceneIndexType.CONTACTS, profile); #endif } catch (Exception ex) { return(SendJsonErrorResponse(ex)); } // will be intepreted as an error if Content() is used return(Json(OPERATION_SUCCESSFUL.ToJsonOKData())); }