Ejemplo n.º 1
0
        /// <summary>
        /// Map View Model to Model
        /// </summary>
        /// <param name="bomViewModel"></param>
        /// <returns></returns>
        private BillOfMaterial MapBomToModel(BillOfMaterialViewModel bomViewModel)
        {
            var bom = new BillOfMaterial();

            bom.MapFromViewModel(bomViewModel, (ClaimsIdentity)_principal.Identity);

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

            if (!string.IsNullOrEmpty(bomViewModel.Image))
            {
                bom.Image = ObjectId.Parse(bomViewModel.Image);
            }
            bom.AddedItems = new List <AddToBom>();
            bom.Comments   = new List <BomComment>();
            if (bomViewModel.Groups != null && bomViewModel.Groups.Any())
            {
                bom.Groups = new List <BomGroup>();
                bomViewModel.Groups.ForEach(t =>
                {
                    var bomGroup = MapBomGroupToModel(t);
                    bom.Groups.Add(bomGroup);
                });
            }
            return(bom);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Update Bill Of Material.
        /// </summary>
        /// <param name="bomViewModel"></param>
        /// <param name="fileViewModel"></param>
        /// <returns></returns>
        public IResult UpdateBillOfMaterial(BillOfMaterialViewModel bomViewModel, FileDetails fileViewModel)
        {
            var result = new Result
            {
                Operation = Operation.Update,
                Status    = Status.Success
            };

            try
            {
                #region BOM Update
                var bom = MapBomToModel(bomViewModel);
                var updateDefinition = Builders <BillOfMaterial> .Update
                                       .Set(x => x.Name, bom.Name)
                                       .Set(x => x.Description, bom.Description)
                                       .Set(x => x.ModifiedDate, bom.ModifiedDate)
                                       .Set(x => x.Groups, bom.Groups)
                                       .Set(x => x.Status, bom.Status);

                _bomRepository.UpdateOne(t => t.BomId == ObjectId.Parse(bomViewModel.BomId), updateDefinition);
                #endregion

                #region Update BOM Image
                if (fileViewModel != null)
                {
                    var file = new File();
                    file.MapFromViewModel(fileViewModel, (ClaimsIdentity)_principal.Identity);
                    if (bom.Image == null)
                    {
                        _fileRepository.InsertOne(file);
                        bom.Image = file.FileId;
                        var updateBOMDefinition = Builders <BillOfMaterial> .Update.Set(x => x.Image, bom.Image);

                        _bomRepository.UpdateOne(t => t.BomId == bom.BomId, updateBOMDefinition);
                    }
                    else
                    {
                        var updateImageDefinition = Builders <File> .Update
                                                    .Set(x => x.Name, file.Name)
                                                    .Set(x => x.Content, file.Content)
                                                    .Set(x => x.ContentType, file.ContentType)
                                                    .Set(x => x.ModifiedDate, file.ModifiedDate);

                        _fileRepository.UpdateOne(t => t.FileId == bom.Image, updateImageDefinition);
                    }
                }
                #endregion

                result.Body    = MapBomToViewModel(bom);
                result.Message = BomNotification.Updated;
            }
            catch (Exception e)
            {
                result.Message = e.Message;
                result.Status  = Status.Fail;
            }
            return(result);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
 public BillOfMaterialView(BillOfMaterialViewModel model)
 {
     InitializeComponent();
     DataContext = model;
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Insert Bill Of Material.
        /// </summary>
        /// <param name="bomViewModel"></param>
        /// <param name="fileViewModel"></param>
        /// <returns></returns>
        public IResult CreateBillOfMaterial(BillOfMaterialViewModel bomViewModel, FileDetails fileViewModel)
        {
            bomViewModel.BomId = null;
            var result = new Result
            {
                Operation = Operation.Create,
                Status    = Status.Success
            };

            try
            {
                if (bomViewModel.Type == BomType.Template)
                {
                    bomViewModel.TemplateId = null;
                }
                else
                {
                    if (string.IsNullOrEmpty(bomViewModel.TemplateId))
                    {
                        result.Message = BomNotification.TemplateNotFound;
                        return(result);
                    }
                }

                var bom        = MapBomToModel(bomViewModel);
                var emailClaim = ((ClaimsIdentity)_principal.Identity).GetActiveUserId();
                if (!string.IsNullOrEmpty(emailClaim))
                {
                    if (_configuration["AuthMethod"] == "ad")
                    {
                        var user = _graphRepository.RequestUserDetails(emailClaim).Result;
                        if (user != null)
                        {
                            bom.BomUser = new BomUser
                            {
                                FirstName = user.DisplayName,
                                LastName  = user.Surname,
                                Mail      = user.Mail,
                                Company   = user.Company
                            };
                        }
                    }
                    else
                    {
                        bom.BomUser = new BomUser
                        {
                            FirstName = "Admin",
                            LastName  = "User",
                            Mail      = "*****@*****.**",
                            Company   = "SubquipAdmin"
                        };
                    }
                }
                bom.Status = BomStatus.InProgress;
                _bomRepository.InsertOne(bom);
                if (fileViewModel != null)
                {
                    var file = new File();
                    file.MapFromViewModel(fileViewModel, (ClaimsIdentity)_principal.Identity);
                    _fileRepository.InsertOne(file);
                    bom.Image = file.FileId;
                    var updateDefinition = Builders <BillOfMaterial> .Update.Set(x => x.Image, bom.Image);

                    _bomRepository.UpdateOne(t => t.BomId == bom.BomId, updateDefinition);
                }
                result.Body    = MapBomToViewModel(bom);
                result.Message = BomNotification.Created;
            }
            catch (Exception e)
            {
                result.Message = e.Message;
                result.Status  = Status.Fail;
            }
            return(result);
        }