Exemple #1
0
        public static dataModel.Contact ToDataModel(this coreModel.Contact contact, PrimaryKeyResolvingMap pkMap)
        {
            if (contact == null)
            {
                throw new ArgumentNullException("contact");
            }

            var retVal = new dataModel.Contact();

            contact.ToDataModel(retVal);

            if (retVal.Name == null)
            {
                retVal.Name = retVal.FullName;
            }

            pkMap.AddPair(contact, retVal);

            if (contact.Organizations != null)
            {
                retVal.MemberRelations = new ObservableCollection <dataModel.MemberRelation>();
                foreach (var organization in contact.Organizations)
                {
                    var memberRelation = new dataModel.MemberRelation
                    {
                        AncestorId       = organization,
                        AncestorSequence = 1,
                        DescendantId     = retVal.Id,
                    };
                    retVal.MemberRelations.Add(memberRelation);
                }
            }
            return((dataModel.Contact)retVal);
        }
        public static webModel.Contact ToWebModel(this coreModel.Contact contact)
        {
            var retVal = new webModel.Contact();

            retVal.InjectFrom(contact);

            if (contact.Phones != null)
            {
                retVal.Phones = contact.Phones;
            }
            if (contact.Emails != null)
            {
                retVal.Emails = contact.Emails;
            }
            if (contact.DynamicProperties != null)
            {
                retVal.DynamicProperties = contact.DynamicProperties;
            }
            if (contact.Notes != null)
            {
                retVal.Notes = contact.Notes.Select(x => x.ToWebModel()).ToList();
            }
            if (contact.Addresses != null)
            {
                retVal.Addresses = contact.Addresses.Select(x => x.ToWebModel()).ToList();
            }
            if (contact.SecurityAccounts != null)
            {
                retVal.SecurityAccounts = contact.SecurityAccounts;
            }

            retVal.Organizations = contact.Organizations;

            return(retVal);
        }
Exemple #3
0
 public void CreateNewContact()
 {
     var controller = GetContactController();
     var contact = new Contact
     {
         Id = "testContact1",
         FullName = "Vasa2",
         BirthDate = DateTime.UtcNow,
         Organizations = new[] { "org1" },
         Addresses = new Address[]
         {
             new Address {
             Name = "some name",
             AddressType = AddressType.Shipping,
             City = "london",
             Phone = "+68787687",
             PostalCode = "22222",
             CountryCode = "ENG",
             CountryName = "England",
             Email = "*****@*****.**",
             FirstName = "first name",
             LastName = "last name",
             Line1 = "line 1",
             Organization = "org1"
             }
         }.ToList(),
         Notes = new Note[] { new Note { Title = "1111", Body = "dfsdfs sdf sdf sdf sd" } },
         Emails = new[] { "*****@*****.**", "*****@*****.**" },
         Phones = new[] { "2322232", "32323232" },
         //DynamicPropertyValues = new[] { new DynamicPropertyObjectValue { Property = new DynamicProperty { Name = "testProp", ValueType = DynamicPropertyValueType.ShortText }, Values = new object[] { "sss" } } }.ToList(),
         DefaultLanguage = "ru"
     };
     var result = controller.CreateContact(contact) as OkNegotiatedContentResult<Contact>;
     Assert.IsNotNull(result.Content);
 }
Exemple #4
0
        public coreModel.Contact GetById(string id)
        {
            coreModel.Contact retVal = null;

            using (var repository = _repositoryFactory())
            {
                var entity = repository.GetContactById(id);
                if (entity != null)
                {
                    retVal = entity.ToCoreModel();
                }
            }

            if (retVal != null)
            {
                //Load dynamic properties for contact
                _dynamicPropertyService.LoadDynamicPropertyValues(retVal);

                //Load all security accounts associated with this contact
                var result = Task.Run(() => _securityService.SearchUsersAsync(new UserSearchRequest {
                    MemberId = retVal.Id, TakeCount = int.MaxValue
                })).Result;
                retVal.SecurityAccounts = result.Users.ToList();
            }

            return(retVal);
        }
        public async Task<IHttpActionResult> CreateContact(Contact contact)
        {
            var ret = await Task.FromResult(_contactsProvider.NewContact(contact));
            if (ret != null)
            {
                return Ok(ret);
            }

            return BadRequest();
        }
Exemple #6
0
        /// <summary>
        /// Converting to model type
        /// </summary>
        /// <param name="dbEntity"></param>
        /// <returns></returns>
        public static coreModel.Contact ToCoreModel(this dataModel.Contact dbEntity)
        {
            if (dbEntity == null)
                throw new ArgumentNullException("dbEntity");

            var retVal = new coreModel.Contact();
            dbEntity.ToCoreModel(retVal);
            retVal.Organizations = dbEntity.MemberRelations.Select(x => x.Ancestor).OfType<dataModel.Organization>().Select(x => x.Id).ToList();
            return retVal;
        }
Exemple #7
0
        /// <summary>
        /// Converting to model type
        /// </summary>
        /// <param name="dbEntity"></param>
        /// <returns></returns>
        public static coreModel.Contact ToCoreModel(this dataModel.Contact dbEntity)
        {
            if (dbEntity == null)
            {
                throw new ArgumentNullException("dbEntity");
            }

            var retVal = new coreModel.Contact();

            dbEntity.ToCoreModel(retVal);
            retVal.Organizations = dbEntity.MemberRelations.Select(x => x.Ancestor).OfType <dataModel.Organization>().Select(x => x.Id).ToList();
            return(retVal);
        }
Exemple #8
0
        public coreModel.Contact Create(coreModel.Contact contact)
        {
            var entity = contact.ToDataModel();

            coreModel.Contact retVal = null;
            using (var repository = _repositoryFactory())
            {
                repository.Add(entity);
                CommitChanges(repository);
            }
            retVal = GetById(entity.Id);
            return(retVal);
        }
Exemple #9
0
        public coreModel.Contact GetById(string id)
        {
            coreModel.Contact retVal = null;
            using (var repository = _repositoryFactory())
            {
                var entity = repository.GetContactById(id);
                if (entity != null)
                {
                    retVal = entity.ToCoreModel();
                }
            }

            return(retVal);
        }
        /// <summary>
        /// Converting to model type
        /// </summary>
        /// <param name="dbEntity"></param>
        /// <returns></returns>
        public static coreModel.Contact ToCoreModel(this dataModel.Contact dbEntity)
        {
            if (dbEntity == null)
                throw new ArgumentNullException("dbEntity");

            var retVal = new coreModel.Contact();
            retVal.InjectFrom(dbEntity);

            retVal.Addresses = dbEntity.Addresses.Select(x => x.ToCoreModel()).ToList();
            retVal.Emails = dbEntity.Emails.Select(x => x.Address).ToList();
            retVal.Notes = dbEntity.Notes.Select(x => x.ToCoreModel()).ToList();
            retVal.Phones = dbEntity.Phones.Select(x => x.Number).ToList();
            retVal.Organizations = dbEntity.MemberRelations.Select(x => x.Ancestor).OfType<dataModel.Organization>().Select(x => x.Id).ToList();
            return retVal;

        }
Exemple #11
0
        public coreModel.Contact Create(coreModel.Contact contact)
        {
            var entity = contact.ToDataModel();

            using (var repository = _repositoryFactory())
            {
                repository.Add(entity);
                CommitChanges(repository);
            }

            _dynamicPropertyService.SaveDynamicPropertyValues(contact);

            var retVal = GetById(entity.Id);

            return(retVal);
        }
Exemple #12
0
        /// <summary>
        /// Converting to model type
        /// </summary>
        /// <param name="dbEntity"></param>
        /// <returns></returns>
        public static coreModel.Contact ToCoreModel(this dataModel.Contact dbEntity)
        {
            if (dbEntity == null)
            {
                throw new ArgumentNullException("dbEntity");
            }

            var retVal = new coreModel.Contact();

            retVal.InjectFrom(dbEntity);

            retVal.Addresses     = dbEntity.Addresses.OrderBy(x => x.Id).Select(x => x.ToCoreModel()).ToList();
            retVal.Emails        = dbEntity.Emails.OrderBy(x => x.Id).Select(x => x.Address).ToList();
            retVal.Notes         = dbEntity.Notes.OrderBy(x => x.Id).Select(x => x.ToCoreModel()).ToList();
            retVal.Phones        = dbEntity.Phones.OrderBy(x => x.Id).Select(x => x.Number).ToList();
            retVal.Organizations = dbEntity.MemberRelations.Select(x => x.Ancestor).OfType <dataModel.Organization>().Select(x => x.Id).ToList();
            return(retVal);
        }
        public static coreModel.Contact ToCoreModel(this webModel.Contact contact)
        {
            var retVal = new coreModel.Contact();
            retVal.InjectFrom(contact);


            if (contact.Phones != null)
                retVal.Phones = contact.Phones;
            if (contact.Emails != null)
                retVal.Emails = contact.Emails;
			if (contact.DynamicProperties != null)
				retVal.DynamicProperties = contact.DynamicProperties;
            if (contact.Notes != null)
                retVal.Notes = contact.Notes.Select(x => x.ToCoreModel()).ToList();
            if (contact.Addresses != null)
                retVal.Addresses = contact.Addresses.Select(x => x.ToCoreModel()).ToList();
            retVal.Organizations = contact.Organizations;

            return retVal;
        }
        public coreModel.Contact GetById(string id)
        {
            coreModel.Contact retVal = null;

            using (var repository = _repositoryFactory())
            {
                var entity = repository.GetContactById(id);
                if (entity != null)
                {
                    retVal = entity.ToCoreModel();
                }
            }

            if (retVal != null)
            {
                _dynamicPropertyService.LoadDynamicPropertyValues(retVal);
            }

            return(retVal);
        }
Exemple #15
0
        public coreModel.Contact Create(coreModel.Contact contact)
        {
            var pkMap  = new PrimaryKeyResolvingMap();
            var entity = contact.ToDataModel(pkMap);

            using (var repository = _repositoryFactory())
            {
                repository.Add(entity);

                CommitChanges(repository);

                pkMap.ResolvePrimaryKeys();
            }

            _dynamicPropertyService.SaveDynamicPropertyValues(contact);

            var retVal = GetById(entity.Id);

            return(retVal);
        }
 public Contact NewContact(Contact newContact)
 {
     return _contactService.Create(newContact);
 }
Exemple #17
0
        public void PartialUpdateContact()
        {
            var controller = GetContactController();
            var contact = new Contact
            {
                Id = "testContact",
                FullName = "ET"
            };

            controller.UpdateContact(contact);

            var result = controller.GetMemberById("testContact") as OkNegotiatedContentResult<Contact>;

            contact = result.Content;
        }
Exemple #18
0
        public static dataModel.Contact ToDataModel(this coreModel.Contact contact, PrimaryKeyResolvingMap pkMap)
        {
            if (contact == null)
            {
                throw new ArgumentNullException("contact");
            }

            var retVal = new dataModel.Contact();

            pkMap.AddPair(contact, retVal);

            retVal.InjectFrom(contact);

            if (contact.Phones != null)
            {
                retVal.Phones = new ObservableCollection <dataModel.Phone>(contact.Phones.Select(x => new dataModel.Phone
                {
                    Number   = x,
                    MemberId = contact.Id
                }));
            }

            if (contact.Emails != null)
            {
                retVal.Emails = new ObservableCollection <dataModel.Email>(contact.Emails.Select(x => new dataModel.Email
                {
                    Address  = x,
                    MemberId = contact.Id
                }));
            }

            if (contact.Addresses != null)
            {
                retVal.Addresses = new ObservableCollection <dataModel.Address>(contact.Addresses.Select(x => x.ToDataModel()));
                foreach (var address in retVal.Addresses)
                {
                    address.MemberId = contact.Id;
                }
            }

            if (contact.Notes != null)
            {
                retVal.Notes = new ObservableCollection <dataModel.Note>(contact.Notes.Select(x => x.ToDataModel()));
                foreach (var note in retVal.Notes)
                {
                    note.MemberId = contact.Id;
                }
            }

            if (contact.Organizations != null)
            {
                retVal.MemberRelations = new ObservableCollection <dataModel.MemberRelation>();
                foreach (var organization in contact.Organizations)
                {
                    var memberRelation = new dataModel.MemberRelation
                    {
                        AncestorId       = organization,
                        AncestorSequence = 1,
                        DescendantId     = retVal.Id
                    };
                    retVal.MemberRelations.Add(memberRelation);
                }
            }
            return(retVal);
        }
        public static GetTaxRequest ToAvaTaxRequest(this VirtoCommerce.Domain.Order.Model.CustomerOrder order, string companyCode, Contact contact, bool commit = false)
        {
            if (order.Addresses != null && order.Addresses.Any() && order.Items != null && order.Items.Any())
            {
                // Document Level Elements
                // Required Request Parameters
                var getTaxRequest = new GetTaxRequest
                {
                    CustomerCode = order.CustomerId,
                    DocDate =
                        order.CreatedDate == DateTime.MinValue
                            ? DateTime.UtcNow.ToString("yyyy-MM-dd")
                            : order.CreatedDate.ToString("yyyy-MM-dd"),
                    CompanyCode = companyCode,
                    Client = "VirtoCommerce,2.x,VirtoCommerce",
                    DetailLevel = DetailLevel.Tax,
                    Commit = commit,
                    DocType = DocType.SalesInvoice,
                    DocCode = order.Number,
                    CurrencyCode = order.Currency.ToString()
                };

                // Best Practice Request Parameters

                // Situational Request Parameters
                // getTaxRequest.CustomerUsageType = "G";
                // getTaxRequest.ExemptionNo = "12345";
                // getTaxRequest.BusinessIdentificationNo = "234243";
                // getTaxRequest.Discount = 50;
                // getTaxRequest.TaxOverride = new TaxOverrideDef();
                // getTaxRequest.TaxOverride.TaxOverrideType = "TaxDate";
                // getTaxRequest.TaxOverride.Reason = "Adjustment for return";
                // getTaxRequest.TaxOverride.TaxDate = "2013-07-01";
                // getTaxRequest.TaxOverride.TaxAmount = "0";

                // Optional Request Parameters
                //getTaxRequest.PurchaseOrderNo = order.Number;
                //getTaxRequest.ReferenceCode = "ref123456";
                //getTaxRequest.PosLaneCode = "09";

                //add customer tax exemption code to cart if exists
                getTaxRequest.ExemptionNo = contact.GetDynamicPropertyValue("Tax exempt", string.Empty);

                string destinationAddressIndex = "0";

                // Address Data
                var addresses = new List<Address>();

                foreach (var address in order.Addresses.Select((x, i) => new { Value = x, Index = i }))
                {
                    addresses.Add(new Address
                    {
                        AddressCode = address.Index.ToString(CultureInfo.InvariantCulture),
                        Line1 = address.Value.Line1,
                        City = address.Value.City,
                        Region = address.Value.RegionName ?? address.Value.RegionId,
                        PostalCode = address.Value.PostalCode,
                        Country = address.Value.CountryName
                    });

                    if (address.Value.AddressType == AddressType.Shipping
                        || address.Value.AddressType == AddressType.Shipping)
                        destinationAddressIndex = address.Index.ToString(CultureInfo.InvariantCulture);
                }

                getTaxRequest.Addresses = addresses.ToArray();

                // Line Data
                // Required Parameters

                getTaxRequest.Lines = order.Items.Select(li =>
                    new Line
                    {
                        LineNo = li.Id,
                        ItemCode = li.ProductId,
                        Qty = li.Quantity,
                        Amount = li.Price * li.Quantity,
                        OriginCode = destinationAddressIndex, //TODO set origin address (fulfillment?)
                        DestinationCode = destinationAddressIndex,
                        Description = li.Name,
                        TaxCode = li.TaxType
                    }
                    ).ToList();

                //Add shipments as lines
                if (order.Shipments != null && order.Shipments.Any())
                {
                    order.Shipments.ForEach(sh =>
                    getTaxRequest.Lines.Add(new Line
                    {
                        LineNo = sh.Id ?? sh.ShipmentMethodCode,
                        ItemCode = sh.ShipmentMethodCode,
                        Qty = 1,
                        Amount = sh.Sum,
                        OriginCode = destinationAddressIndex, //TODO set origin address (fulfillment?)
                        DestinationCode = destinationAddressIndex,
                        Description = sh.ShipmentMethodCode,
                        TaxCode = sh.TaxType ?? "FR"
                    })
                    );
                }

                return getTaxRequest;
            }
            return null;
        }
        public static GetTaxRequest ToAvaTaxAdjustmentRequest(this VirtoCommerce.Domain.Order.Model.CustomerOrder modifiedOrder, string companyCode, Contact contact, VirtoCommerce.Domain.Order.Model.CustomerOrder originalOrder, bool commit = false)
        {
            if (modifiedOrder.Addresses != null && modifiedOrder.Addresses.Any() && originalOrder.Items != null && originalOrder.Items.Any())
            {
                // Document Level Elements
                // Required Request Parameters
                var getTaxRequest = new GetTaxRequest
                {
                    CustomerCode = modifiedOrder.CustomerId,
                    DocDate = DateTime.UtcNow.ToString("yyyy-MM-dd"),
                    CompanyCode = companyCode,
                    Client = "VirtoCommerce,2.x,VirtoCommerce",
                    DocCode = string.Format("{0}.{1}", originalOrder.Number, DateTime.UtcNow.ToString("yy-MM-dd-hh-mm")),
                    DetailLevel = DetailLevel.Tax,
                    Commit = commit,
                    DocType = DocType.ReturnInvoice,
                    TaxOverride = new TaxOverrideDef
                    {
                        TaxOverrideType = "TaxDate",
                        Reason = "Adjustment for return",
                        TaxDate = originalOrder.CreatedDate == DateTime.MinValue
                            ? DateTime.UtcNow.ToString("yyyy-MM-dd")
                            : originalOrder.CreatedDate.ToString("yyyy-MM-dd"),
                        TaxAmount = "0"
                    }
                };

                // Best Practice Request Parameters

                // Situational Request Parameters
                // getTaxRequest.CustomerUsageType = "G";
                // getTaxRequest.ExemptionNo = "12345";
                // getTaxRequest.BusinessIdentificationNo = "234243"; //for VAT tax calculations
                // getTaxRequest.Discount = 50;

                // Optional Request Parameters
                //getTaxRequest.PurchaseOrderNo = order.Number;
                getTaxRequest.ReferenceCode = originalOrder.Number;
                //getTaxRequest.PosLaneCode = "09";
                getTaxRequest.CurrencyCode = modifiedOrder.Currency.ToString();

                //add customer tax exemption code to cart if exists
                getTaxRequest.ExemptionNo = contact.GetDynamicPropertyValue("Tax exempt", string.Empty);

                string destinationAddressIndex = "0";

                // Address Data
                var addresses = new List<Address>();

                foreach (var address in modifiedOrder.Addresses.Select((x, i) => new { Value = x, Index = i }))
                {
                    addresses.Add(new Address
                    {
                        AddressCode = address.Index.ToString(CultureInfo.InvariantCulture),
                        Line1 = address.Value.Line1,
                        City = address.Value.City,
                        Region = address.Value.RegionName ?? address.Value.RegionId,
                        PostalCode = address.Value.PostalCode,
                        Country = address.Value.CountryName
                    });

                    if (address.Value.AddressType == AddressType.Shipping
                        || address.Value.AddressType == AddressType.Shipping)
                        destinationAddressIndex = address.Index.ToString(CultureInfo.InvariantCulture);
                }

                getTaxRequest.Addresses = addresses.ToArray();

                // Line Data
                // Required Parameters

                getTaxRequest.Lines = originalOrder.Items.Where(i => !modifiedOrder.Items.Any(mli => mli.Id.Equals(i.Id)) || i.Quantity > (modifiedOrder.Items.Single(oi => oi.Id.Equals(i.Id)).Quantity)).Select(li =>
                    new Line
                    {
                        LineNo = li.Id,
                        ItemCode = li.ProductId,
                        Qty = modifiedOrder.Items.Any(mli => mli.Id.Equals(li.Id)) ? Math.Abs(li.Quantity - modifiedOrder.Items.Single(oi => oi.Id.Equals(li.Id)).Quantity) : li.Quantity,
                        Amount = modifiedOrder.Items.Any(mli => mli.Id.Equals(li.Id)) ? -(li.Price * li.Quantity - modifiedOrder.Items.Single(oi => oi.Id.Equals(li.Id)).Price * modifiedOrder.Items.Single(mli => mli.Id.Equals(li.Id)).Quantity) : -li.Price * li.Quantity,
                        OriginCode = destinationAddressIndex, //TODO set origin address (fulfillment?)
                        DestinationCode = destinationAddressIndex,
                        Description = li.Name,
                        TaxCode = li.TaxType
                    }
                    ).ToList();

                return getTaxRequest;
            }
            return null;
        }
Exemple #21
0
 public IHttpActionResult UpdateContact(coreModel.Contact contact)
 {
     return(UpdateMember(contact));
 }