Exemplo n.º 1
0
        /// <summary>
        /// Map bom model to view model
        /// </summary>
        /// <param name="bom"></param>
        /// <returns></returns>
        private BillOfMaterialViewModel MapBomToViewModel(BillOfMaterial bom)
        {
            var bomViewModel = new BillOfMaterialViewModel();

            bomViewModel.MapFromModel(bom);

            if (bom.TemplateId != null)
            {
                bomViewModel.TemplateId = bom.TemplateId.ToString();
            }

            if (bom.Image != null)
            {
                bomViewModel.Image = bom.Image.ToString();
            }

            bomViewModel.BomUser = MapBomUserToViewModel(bom.BomUser);

            if (bom.Groups != null && bom.Groups.Any())
            {
                bomViewModel.Groups = new List <BomGroupViewModel>();
                bom.Groups.ForEach(t =>
                {
                    var bomGroupViewModel = MapBomGroupToViewModel(t);
                    bomViewModel.Groups.Add(bomGroupViewModel);
                });
            }

            if (bom.Comments != null && bom.Comments.Any())
            {
                bomViewModel.Comments = bom.Comments.Select(t =>
                {
                    var bomCommentViewModel = new BomCommentViewModel();
                    bomCommentViewModel.MapFromModel(t);
                    return(bomCommentViewModel);
                }).ToList();
            }

            if (bom.Option != null)
            {
                bomViewModel.Option = new BomOptionViewModel();
                if (bom.Option.License != null)
                {
                    bomViewModel.Option.License = bom.Option.License.ToString();
                }
                if (bom.Option.Owner != null)
                {
                    bomViewModel.Option.Owner = bom.Option.Owner.ToString();
                }
                if (bom.Option.Location != null)
                {
                    bomViewModel.Option.Location = bom.Option.Location.ToString();
                }
            }

            return(bomViewModel);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get list of bom's viewmodel for logged user
        /// </summary>
        /// <param name="search"></param>
        /// <param name="userid"></param>
        /// <returns></returns>
        public List <BillOfMaterialViewModel> GetSearchedBom(SearchSortModel search, string userid)
        {
            var bomViewModels = new List <BillOfMaterialViewModel>();
            var allBoms       = _bomRepository.GetAllBillOfMaterial(search, userid);

            if (allBoms.Any())
            {
                bomViewModels = allBoms.Select(t =>
                {
                    var bomViewModel = new BillOfMaterialViewModel();
                    bomViewModel.MapFromModel(t);
                    bomViewModel.TemplateId = t.TemplateId.ToString();
                    if (t.BomUser == null)
                    {
                        return(bomViewModel);
                    }
                    var bomUserViewModel = new BomUserViewModel();
                    bomViewModel.BomUser = (BomUserViewModel)bomUserViewModel.MapFromModel(t.BomUser);
                    return(bomViewModel);
                }).ToList();
            }
            return(bomViewModels);
        }