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