Ejemplo n.º 1
0
        public async Task <ApiResult <GetByIdMaterial> > GetByIdMaterial(int id)
        {
            var materials = await _context.Materials.FindAsync(id);

            if (materials == null)
            {
                return(new ApiErrorResult <GetByIdMaterial>("Nguyên vật liệu không tồn tại"));
            }

            var query = await(from s in _context.Materials
                              join g in _context.MaterialsTypes on s.IdMaterialsType equals g.Id
                              join d in _context.Packs on s.Id equals d.IdMaterials
                              where s.Id == id
                              select new { s, g, d }).FirstAsync();

            var result = new GetByIdMaterial()
            {
                Id               = materials.Id,
                Code             = materials.Code,
                Name             = materials.Name,
                Image            = materials.Image,
                IdMaterialType   = materials.IdMaterialsType,
                NameMaterialType = query.g.Name,
                Description      = materials.Description,
                Amount           = materials.Amount,
                Reminder         = materials.Reminder
            };

            result.NamePackDefault = query.s.Packs.Where(x => x.Default == true).Select(x => x.Name).First();

            var pack = from s in _context.Materials
                       join d in _context.Packs on s.Id equals d.IdMaterials
                       where s.Id == id && d.Default != true
                       select new { s, d };

            result.Pack = pack.Select(
                i => new GetMaterialPack()
            {
                Name    = i.d.Name,
                Value   = i.d.Value,
                Default = i.d.Default,
                Change  = (long)(result.Amount / i.d.Value)
            }
                ).ToList();
            return(new ApiSuccessResult <GetByIdMaterial>(result));
        }
Ejemplo n.º 2
0
        public async Task <GetByIdMaterial> GetByIdMaterial(int id)
        {
            var result = await _materialApiClient.GetByIdMaterial(id);

            var data = new GetByIdMaterial()
            {
                Id               = result.ResultObj.Id,
                Code             = result.ResultObj.Code,
                Name             = result.ResultObj.Name,
                Image            = result.ResultObj.Image,
                Description      = result.ResultObj.Description,
                IdMaterialType   = result.ResultObj.IdMaterialType,
                NameMaterialType = result.ResultObj.NameMaterialType,
                Amount           = result.ResultObj.Amount,
                Pack             = result.ResultObj.Pack,
                Reminder         = result.ResultObj.Reminder,
                NamePackDefault  = result.ResultObj.NamePackDefault
            };

            return(data);
        }