コード例 #1
0
        public ActionResult Delete(long id)
        {
            // is order in use
            var order = repository.GetOrder(subdomainid.Value, id);

            if (order == null)
            {
                return(SendJsonErrorResponse("Order not found"));
            }

            var transaction = new Transaction(order, repository, sessionid.Value);
            var status      = transaction.GetOrderStatus();

            if (status != OrderStatus.DRAFT && status != OrderStatus.SENT)
            {
                return(SendJsonErrorResponse("Unable to delete. Order has already been viewed."));
            }

            try
            {
#if LUCENE
                var indexer = new LuceneWorker(db, MASTERdomain.ToIdName());
                indexer.DeleteFromIndex(LuceneIndexType.TRANSACTION, id);
#endif
                repository.UpdateCounters(subdomainid.Value, -1, CounterType.ORDERS_SENT);

                transaction.DeleteOrder();
            }
            catch (Exception ex)
            {
                return(SendJsonErrorResponse(ex));
            }

            return(Json(id.ToJsonOKData()));
        }
コード例 #2
0
        public ActionResult Delete(string id)
        {
            var contactids = id.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse);
            var successIDs = new List <long>();

            foreach (var contactid in contactids)
            {
                if (repository.IsContactInUse(contactid))
                {
                    continue;
                }
#if LUCENE
                var indexer = new LuceneWorker(db, MASTERdomain.ToIdName());
                indexer.DeleteFromIndex(LuceneIndexType.CONTACTS, contactid);
#endif
                // delete necessary data
                repository.DeleteUser(contactid, subdomainid.Value);
                successIDs.Add(contactid);
            }

            return(Json(successIDs.ToJsonOKData()));
        }
コード例 #3
0
        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()));
        }