public IResult AddCommentToBOM([FromBody] BomCommentViewModel bomCommentViewModel)
        {
            IResult result = null;

            result = _billOfMaterialsManager.SaveCommentForBOM(bomCommentViewModel);
            return(result);
        }
Пример #2
0
        /// <summary>
        /// Add Comment to BOM.
        /// </summary>
        /// <param name="bomCommentViewModel"></param>
        /// <returns></returns>
        public IResult SaveCommentForBOM(BomCommentViewModel bomCommentViewModel)
        {
            var result = new Result
            {
                Operation = Operation.Create,
                Status    = Status.Success
            };

            try
            {
                var bomComment = new BomComment();
                bomComment.MapFromViewModel(bomCommentViewModel, (ClaimsIdentity)_principal.Identity);
                var lstBomComments = new List <BomComment>();
                lstBomComments.Add(bomComment);
                var updateDefinition = Builders <BillOfMaterial> .Update.Set(t => t.ModifiedDate, GenericHelper.CurrentDate).AddToSet(t => t.Comments, bomComment);

                _bomRepository.UpdateOne(t => t.BomId.Equals(ObjectId.Parse(bomCommentViewModel.RegardingId)), updateDefinition);
                result.Message = BomNotification.CommentCreated;
            }
            catch (Exception e)
            {
                result.Message = e.Message;
                result.Status  = Status.Fail;
            }
            return(result);
        }
Пример #3
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);
        }
Пример #4
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);
        }