Click here to Skip to main content
15,886,055 members
Articles / Web Development / HTML

Design and Develop a website using ASP.NET MVC 4, EF, Knockoutjs and Bootstrap : Part - 2

Rate me:
Please Sign up or sign in to vote.
4.92/5 (74 votes)
13 Jan 2013CPOL10 min read 218.1K   15.7K   168  
Design a website architecture that must be simple, easily understandable by any web designer using asp.net MVC, EF, Knockoutjs and Bootstrap
using Application.Core.ProfileModule.AddressAggregate;
using Application.Core.ProfileModule.PhoneAggregate;
using Application.Core.ProfileModule.ProfileAggregate;
using Application.DTO;
using Application.DTO.ProfileModule;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Application.Manager.Conversion
{
    public static class Mapping
    {
        public static ProfileDTO ProfileToProfileDTO(Profile profile, List<AddressType> addressTypes, List<PhoneType> phoneTypes)
        {
            ProfileDTO objProfileDTO = new ProfileDTO();
            objProfileDTO.ProfileId = profile.ProfileId;
            objProfileDTO.FirstName = profile.FirstName;
            objProfileDTO.LastName = profile.LastName;
            objProfileDTO.Email = profile.Email;
            objProfileDTO.AddressDTO = new List<AddressDTO>();
            objProfileDTO.PhoneDTO = new List<PhoneDTO>();

            foreach (var profileAddress in profile.ProfileAddresses)
            {
                AddressDTO objAddressDTO = AddressToAddressDTO(profileAddress.Address);
                objAddressDTO.AddressTypeId = profileAddress.AddressTypeId;
                objProfileDTO.AddressDTO.Add(objAddressDTO);
            }

            foreach (var profilePhone in profile.ProfilePhones)
            {
                PhoneDTO objPhoneDTO = PhoneToPhoneDTO(profilePhone.Phone);
                objPhoneDTO.PhoneTypeId = profilePhone.PhoneTypeId;
                objProfileDTO.PhoneDTO.Add(objPhoneDTO);
            }
            return objProfileDTO;
        }

        public static AddressDTO AddressToAddressDTO(Address address)
        {
            AddressDTO objAddressDTO = new AddressDTO();
            if (address != null)
            {
                objAddressDTO.AddressId = address.AddressId;
                objAddressDTO.AddressLine1 = address.AddressLine1;
                objAddressDTO.AddressLine2 = address.AddressLine2;
                objAddressDTO.ZipCode = address.ZipCode;
                objAddressDTO.Country = address.Country;
                objAddressDTO.State = address.State;
                objAddressDTO.City = address.City;
            }
            return objAddressDTO;
        }

        public static List<AddressTypeDTO> AddressTypeToAddressTypeDTO(List<AddressType> addressTypes)
        {
            List<AddressTypeDTO> lstAddressTypeDTO = new List<AddressTypeDTO>();
 
            foreach (AddressType addressType in addressTypes)
            {
                AddressTypeDTO objAddressTypeDTO = new AddressTypeDTO();
                objAddressTypeDTO.AddressTypeId = addressType.AddressTypeId;
                objAddressTypeDTO.Name = addressType.Name;
                lstAddressTypeDTO.Add(objAddressTypeDTO);
            }
            return lstAddressTypeDTO;
        }

        public static List<PhoneTypeDTO> PhoneTypeToPhoneTypeDTO(List<PhoneType> phoneTypes)
        {
            List<PhoneTypeDTO> lstPhoneTypeDTO = new List<PhoneTypeDTO>();

            foreach (PhoneType phoneType in phoneTypes)
            {
                PhoneTypeDTO objPhoneTypeDTO = new PhoneTypeDTO();
                objPhoneTypeDTO.PhoneTypeId = phoneType.PhoneTypeId;
                objPhoneTypeDTO.Name = phoneType.Name;
                lstPhoneTypeDTO.Add(objPhoneTypeDTO);
            }
            return lstPhoneTypeDTO;
        }

        public static PhoneDTO PhoneToPhoneDTO(Phone phone)
        {
            PhoneDTO objPhoneDTO = new PhoneDTO();
            if (phone != null)
            {
                objPhoneDTO.PhoneId = phone.PhoneId;
                objPhoneDTO.Number = phone.Number;
            }
            return objPhoneDTO;
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions