Esempio n. 1
0
 private AddAssemblyComponentVM MapAddAssemblyComponentVM(AssemblyComponent component) =>
 new AddAssemblyComponentVM
 {
     ComponentId = component.ComponentId,
     Quantity    = component.Quantity,
     Type        = component.BaseComponent.Type
 };
        public async Task <IActionResult> Post(AddAssemblyComponentVM model)
        {
            var assemblyComponent = (AssemblyComponent)null;

            try
            {
                var assembly = await AppContext.Assemblies.FirstOrDefaultAsync(x => x.Id == model.AssemblyId);

                var component = await GetQuery(model.Type).FirstOrDefaultAsync(x => x.Id == model.ComponentId);

                var componentType = await AppContext.ComponentTypes.FirstOrDefaultAsync(x => x.Id == (int)model.Type);

                assemblyComponent = new AssemblyComponent
                {
                    Assembly      = assembly,
                    ComponentId   = component.Id,
                    ComponentType = componentType,
                    Quantity      = model.Quantity,
                };
                AppContext.AssemblyComponents.Add(assemblyComponent);
                await AppContext.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }

            return(CreatedAtAction(nameof(Post), assemblyComponent));
        }
Esempio n. 3
0
 private UpdateAssemblyComponentVM MapUpdateAssemblyComponentVM(AssemblyComponent component) =>
 new UpdateAssemblyComponentVM
 {
     AssemblyComponentId = component.Id,
     Quantity            = component.Quantity
 };