Exemplo n.º 1
0
        public static ClientTermViewModel ToModel(Terms term, bool withPositions, bool withMaterials)
        {
            var positions = new List<ClientTermPositionViewModel>();
            var materials = new List<ClientTermMaterialViewModel>();

            if (withPositions)
            {
                positions = PositionModels(term);
            }

            if(withMaterials)
            {
                materials = term.TermPositions.Where(o => !o.DeleteDate.HasValue).SelectMany(o => o.TermPositionMaterialRsps).ToList().
                    Select(positionMaterialRsp => new ClientTermMaterialViewModel()
                    {
                        Id = positionMaterialRsp.Id,
                        MaterialId = positionMaterialRsp.MaterialId,
                        Description = positionMaterialRsp.Materials.Name,
                        Number = positionMaterialRsp.Materials.Number,
                        Amount = positionMaterialRsp.Amount,
                        PlannedAmount = positionMaterialRsp.TermPositions.Amount,
                        TermId = term.Id
                    }).ToList();

                if (term.Positions != null && term.Positions.Count != 0)
                {
                    materials.AddRange(term.Positions.Where(o => !o.DeleteDate.HasValue && o.MaterialId.HasValue).ToList().
                        Select(position => new ClientTermMaterialViewModel()
                        {
                            Id = position.Id,
                            MaterialId = position.MaterialId.Value,
                            Description = position.Materials.Name,
                            Number = position.Materials.Number,
                            Amount = position.Amount,
                            TermId = term.Id
                        }).ToList());
                }
            }

            return new ClientTermViewModel()
            {
                Id = term.Id,
                FromDate = String.Format("{0}", term.Date.ToString("HH:mm")),
                ToDate = String.Format("{0}", term.Date.AddMinutes(term.Duration).ToString("HH:mm")),
                Address = String.Format("{0} {1} {2}", term.Orders.Street, term.Orders.Zip, term.Orders.City),
                Status = term.Status,
                Positions = positions,
                Materials = materials,
                //IsFirstTerm 
            };
        }
Exemplo n.º 2
0
        public static List<ClientTermPositionViewModel> PositionModels(Terms term)
        {
            var result = new List<ClientTermPositionViewModel>();

            var positions = term.TermPositions.Where(o => !o.DeleteDate.HasValue && o.Positions.ProductId.HasValue).ToList();
            for (int i = 0; i < positions.Count; i++)
            {
                var position = positions[i];
                result.Add(new ClientTermPositionViewModel()
                {
                    Id = position.Id,
                    Number = (i + 1).ToString(),
                    Description = position.Positions.Products.Name,
                    PlannedAmount = position.Amount.ToString(),
                    TermId = position.TermId,
                    ProccessedAmount = position.ProccessedAmount,
                });
            }

            return result;
        }
Exemplo n.º 3
0
        private string ReplacePositionWithDescription(Terms term, string xmlMainXMLDoc)
        {
            var xmlDoc = XDocument.Parse(xmlMainXMLDoc);
            var temp = xmlDoc.Descendants().LastOrDefault(o => o.Value.Contains("#PositionDescription"));
            var parentTableElement = GetParentElementByName(temp, "<w:tr ");

            if (parentTableElement != null)
            {
                var prevTableElem = parentTableElement;

                var positions = term.TermPositions != null ? term.TermPositions.Where(o => !o.DeleteDate.HasValue).ToList() :
                    new List<TermPositions>();

                foreach (var position in positions.Where(o => o.ProccessedAmount.HasValue))
                {
                    if (position.ProccessedAmount.Value > 0)
                    {
                        var elem = XElement.Parse(ReplaceFieldValue(parentTableElement.ToString(), "#PositionDescription", position.Positions.Products.Name).
                            Replace("#Amount", position.ProccessedAmount.Value.ToString()).
                            Replace("#PositionNumber", position.Positions.Products.Number));

                        prevTableElem.AddAfterSelf(elem);
                        prevTableElem = elem;
                    }

                    if (position.TermPositionMaterialRsps != null && position.TermPositionMaterialRsps.Count != 0)
                    {
                        foreach (var material in position.TermPositionMaterialRsps)
                        {
                            var elem = XElement.Parse(ReplaceFieldValue(parentTableElement.ToString(), "#PositionDescription", material.Materials.Name).
                            Replace("#Amount", material.Amount.HasValue ? material.Amount.Value.ToString() : String.Empty).
                            Replace("#PositionNumber", material.Materials.Number));

                            prevTableElem.AddAfterSelf(elem);
                            prevTableElem = elem;
                        }
                    }
                }

                if (term.Positions != null && term.Positions.Count != 0)
                {
                    foreach (var position in term.Positions.Where(o => !o.DeleteDate.HasValue && o.MaterialId.HasValue))
                    {
                        var elem = XElement.Parse(ReplaceFieldValue(parentTableElement.ToString(), "#PositionDescription", position.Materials.Name).
                            Replace("#Amount", position.Amount.ToString()).
                            Replace("#PositionNumber", position.Materials.Number));

                        prevTableElem.AddAfterSelf(elem);
                        prevTableElem = elem;
                    }
                }

                parentTableElement.Remove();
            }

            return xmlDoc.Root.ToString();
        }