public static TipForm ToTipForm(this Branch branch)
        {
            var tipForm = EnitiyExtensionsMapper.MapPublicProperties <Branch, TipForm>(branch);

            MapWebAddresses(branch, tipForm);
            MapGeoJsonToPoint(branch, tipForm);
            MapPhones(branch, tipForm);
            MapDiscount(branch, tipForm);
            tipForm.Categories = branch.CategoryIds?.ToList() ?? new List <string>();
            return(EnitiyExtensionsMapper.MapLocalizableToFlatProperties(branch, tipForm));
        }
        public static Branch ToBranch(this TipForm tipForm)
        {
            var branch = EnitiyExtensionsMapper.MapPublicProperties <TipForm, Branch>(tipForm);

            MapWebAddresses(tipForm, branch);
            MapPointToGeoJson(tipForm, branch);
            MapPhones(tipForm, branch);
            MapDiscount(tipForm, branch);
            branch.CategoryIds = tipForm.Categories;
            return(EnitiyExtensionsMapper.MapFlatToLocalizableProperties(tipForm, branch));
        }
        private static void MapWebAddresses(TipForm tipForm, Branch branch)
        {
            branch.WebAddresses = new List <WebAddress>();

            if (tipForm.WebAddresses == null || tipForm.WebAddresses.Count == 0)
            {
                return;
            }

            var addresses = new List <WebAddress>();

            foreach (var webAddress in tipForm.WebAddresses)
            {
                var address = EnitiyExtensionsMapper.MapPublicProperties <WebAddressItem, WebAddress>(webAddress);
                addresses.Add(address);
            }

            branch.WebAddresses = addresses;
        }
        private static void MapWebAddresses(Branch branch, TipForm tipForm)
        {
            tipForm.WebAddresses = new List <WebAddressItem>();

            if (branch.WebAddresses == null || !branch.WebAddresses.Any())
            {
                return;
            }

            var addresses = new List <WebAddressItem>();

            foreach (var webAddress in branch.WebAddresses)
            {
                var address = EnitiyExtensionsMapper.MapPublicProperties <WebAddress, WebAddressItem>(webAddress);
                addresses.Add(address);
            }

            var index = 0;

            addresses.ForEach(x => x.Index = ++index);

            tipForm.WebAddresses = addresses;
        }