/// <summary> /// get all addresses of user /// </summary> /// <param name="UserId"></param> /// <returns>AddresssDTO</returns> public AddresssDTO GetAllAddress(Guid UserId) { AddresssDTO addressDto = addressDatabase.GetAllAddress(UserId); if (addressDto.Addresses.Count() > 0) { return(addressDto); } else { throw new Exception(); } }
/// <summary> /// databse get all addresss /// </summary> /// <param name="UserId"></param> /// <returns></returns> public AddresssDTO GetAllAddress(Guid UserId) { IEnumerable <UserAddressMapping> UserAddresssMapping = dbContext.UserAddressMappings.Where(a => a.UserID == UserId).ToList(); Debug.WriteLine(dbContext.UserAddressMappings.Where(a => a.UserID == UserId).ToList()); List <Address> addreses = new List <Address>(); foreach (var useraddress in UserAddresssMapping) { addreses.Add(useraddress.Address); } AddresssDTO addressDTO = new AddresssDTO(); addressDTO.Addresses = AddresssMapper.Map <IEnumerable <Address>, IEnumerable <AddressDTO> >(addreses); return(addressDTO); }
public ActionResult Address() { AddressBusiness addressBusiness = new AddressBusiness(); Guid UserID = new Guid(Session["userId"].ToString()); var addressViewConfig = new MapperConfiguration(cfg => { cfg.CreateMap <AddresssDTO, AddresssViewModel>(); }); IMapper addressMapper = new Mapper(addressViewConfig); try { AddresssDTO address = addressBusiness.GetAllAddress(UserID); AddresssViewModel addressViewModel = new AddresssViewModel(); addressViewModel = addressMapper.Map <AddresssDTO, AddresssViewModel>(address); return(View(addressViewModel)); } catch (Exception) { //if address not exist return new form return(View("NewAddress")); } }