Ejemplo n.º 1
0
 public async Task <bool> Create(Time_zone item)
 {
     try
     {
         db.Time_zones.Add(item);
         db.SaveChanges();
         return(true);
     }
     catch { return(false); }
 }
Ejemplo n.º 2
0
 public async Task <bool> Create(Country item)
 {
     try
     {
         db.Countries.Add(item);
         db.SaveChanges();
         return(true);
     }
     catch (Exception ex) { Console.Out.WriteLine(ex.Message); return(false); }
 }
Ejemplo n.º 3
0
        public async Task <bool> Delete(string id)
        {
            try
            {
                User user = await db.Users.FindAsync(id);

                if (user != null)
                {
                    db.Users.Remove(user);
                    db.SaveChanges();
                    return(true);
                }
            }
            catch (Exception ex) {  }
            return(false);
        }
 public void SaveInventoryItem(InventoryItem inventoryItem)
 {
     using (var context = new SBContext())
     {
         context.InventoryItems.Add(inventoryItem);
         context.SaveChanges();
     }
 }
Ejemplo n.º 5
0
 public async Task <bool> Create(Currency item)
 {
     try
     {
         db.Currencies.Add(item);
         db.SaveChanges();
         return(true);
     }
     catch { return(false); }
 }
        public InventoryItem DeleteInventoryItem(int ID)
        {
            using (var context = new SBContext())
            {
                var item = context.InventoryItems.Find(ID);
                context.InventoryItems.Remove(item);
                context.SaveChanges();

                return(item);
            }
        }
Ejemplo n.º 7
0
 public async Task<bool> Delete(int id)
 {
     try
     {
         Business business = db.Businesses.Find(id);
         if (business != null)
         {
             db.Businesses.Remove(business);
             db.SaveChanges();
             return true;
         }
     }
     catch (Exception ex) { Console.Out.WriteLine(ex.Message); }
     return false;
 }
Ejemplo n.º 8
0
        public void CriarPedido(Pedido pedido, List <CarrinhoCompraItem> carrinhoCompraItems)
        {
            _context.Add(pedido);

            foreach (var item in carrinhoCompraItems)
            {
                var itenspedido = new ItensPedido()
                {
                    Quantidade = item.Quantidade,
                    ProdutoID  = item.Produto.ID,
                    PedidoID   = pedido.ID,
                    Preco      = item.Produto.Preco
                };
                _context.ItensPedidos.Add(itenspedido);
            }
            _context.SaveChanges();
        }
 public Categoria AddCategoria(Categoria categoria)
 {
     _context.Add(categoria);
     _context.SaveChanges();
     return(categoria);
 }
Ejemplo n.º 10
0
        public async Task <bool> Update(Slot slot)
        {
            try
            {
                var initialSlot = await db.Slots.FindAsync(slot.Id);

                if (initialSlot != null)
                {
                    initialSlot.SlotDateTime     = slot.SlotDateTime;
                    initialSlot.Duration         = slot.Duration;
                    initialSlot.IsPadding        = slot.IsPadding;
                    initialSlot.PaddingAfter     = slot.PaddingAfter;
                    initialSlot.Reiteration      = slot.Reiteration;
                    initialSlot.Price            = slot.Price;
                    initialSlot.Note             = slot.Note;
                    initialSlot.Status           = slot.Status;
                    initialSlot.IsTimeBlock      = slot.IsTimeBlock;
                    initialSlot.IsReminderNeeded = slot.IsReminderNeeded;
                    initialSlot.ReminderInterval = slot.ReminderInterval;

                    if (initialSlot.Employee.Id != slot.Employee.Id)
                    {
                        var employee     = db.Employees.Include("SlotsOwners").Single(s => s.Id == initialSlot.Employee.Id);
                        var slotToDelete = employee.SlotsOwners.FirstOrDefault(ol => ol.Id == initialSlot.Id);
                        if (slotToDelete != null)
                        {
                            employee.SlotsOwners.Remove(slotToDelete);
                        }
                        initialSlot.Employee = slot.Employee;
                    }

                    if (initialSlot.Country.Id != slot.Country.Id)
                    {
                        var country      = db.Countries.Include("Slots").Single(s => s.Id == initialSlot.Country.Id);
                        var slotToDelete = country.Slots.FirstOrDefault(ol => ol.Id == initialSlot.Id);
                        if (slotToDelete != null)
                        {
                            country.Slots.Remove(slotToDelete);
                        }
                        initialSlot.Country = slot.Country;
                    }

                    if (initialSlot.Responsible.Id != slot.Responsible.Id)
                    {
                        var employeeR    = db.Employees.Include("Responsibles").Single(s => s.Id == initialSlot.Responsible.Id);
                        var slotToDelete = employeeR.Responsibles.FirstOrDefault(ol => ol.Id == initialSlot.Id);
                        if (slotToDelete != null)
                        {
                            employeeR.Responsibles.Remove(slotToDelete);
                        }
                        initialSlot.Responsible = slot.Responsible;
                    }

                    if (initialSlot.Service.Id != slot.Service.Id)
                    {
                        var service      = db.Services.Include("Slots").Single(s => s.Id == initialSlot.Service.Id);
                        var slotToDelete = service.Slots.FirstOrDefault(ol => ol.Id == initialSlot.Id);
                        if (slotToDelete != null)
                        {
                            service.Slots.Remove(slotToDelete);
                        }
                        initialSlot.Service = slot.Service;
                    }

                    db.SaveChanges();
                    return(true);
                }
            }
            catch (Exception ex) { Console.Out.WriteLine(ex.Message); }
            return(false);
        }
 public Produto AddProduto(Produto produto)
 {
     _context.Add(produto);
     _context.SaveChanges();
     return(produto);
 }
 public CarrinhoCompraItem AddCarrinhoCompraItem(CarrinhoCompraItem carrinhoCompraItem)
 {
     _context.Add(carrinhoCompraItem);
     _context.SaveChanges();
     return(carrinhoCompraItem);
 }