예제 #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);
        }
예제 #2
0
        /// <summary>
        /// Get Comments of Bill Of Material For Particular User.
        /// </summary>
        /// <param name="search"></param>
        /// <param name="userid"></param>
        /// <returns></returns>
        public IResult GetCommentsForBom(string bomId)
        {
            var result = new Result
            {
                Operation = Operation.Read,
                Status    = Status.Success
            };

            try
            {
                var bomComments = _bomRepository.GetCommentsForBom(bomId);

                if (bomComments != null && bomComments.Any())
                {
                    var bomCommentViewModels = bomComments.Select(t =>
                    {
                        var bomCommentViewModel = new BomCommentViewModel();
                        bomCommentViewModel.MapFromModel(t);
                        bomCommentViewModel.RegardingId = bomId;
                        return(bomCommentViewModel);
                    }).ToList();

                    result.Body = bomCommentViewModels;
                }
                else
                {
                    result.Message = BomNotification.CommentsNotFound;
                }
            }
            catch (Exception e)
            {
                result.Message = e.Message;
                result.Status  = Status.Fail;
            }
            return(result);
        }