Esempio n. 1
0
 /// <summary>
 /// Maps a db component to a business Component.
 /// </summary>
 /// <param name="component"></param>
 /// <returns></returns>
 public static Data.Component MapComponent(Entities.Component component)
 {
     return(new Data.Component
     {
         ComponentId = component.ComponentId,
         Name = component.Name,
         Cost = component.Cost ?? throw new ArgumentException("Argument cannot be null", nameof(component))
     });
Esempio n. 2
0
        public void RemoveComponent(int id)
        {
            Entities.Component component = _context.Component.FirstOrDefault(c => c.ComponentId == id);

            if (component != null)
            {
                _context.Component.Remove(component);

                Log.Information($"Component with Id {component.ComponentId} has been removed.");
            }
            else
            {
                Log.Error($"Component with Id {component.ComponentId} could not be removed because it does not exist.");
            }
        }
Esempio n. 3
0
        public void UpdateComponent(Component component)
        {
            Entities.Component currentComponent = _context.Component.AsNoTracking().FirstOrDefault(c => c.ComponentId == component.ComponentId);

            if (currentComponent != null)
            {
                Entities.Component newComponent = Mapper.MapComponent(component);

                _context.Entry(currentComponent).CurrentValues.SetValues(newComponent);

                Log.Information($"Component with Id {component.ComponentId} has been updated.");
            }
            else
            {
                Log.Error($"Component with Id {component.ComponentId} could not be updated because it does not exist.");
            }
        }
Esempio n. 4
0
 public void AddComponent(Component component)
 {
     Entities.Component newComponent = Mapper.MapComponent(component);
     _context.Component.Add(newComponent);
 }