예제 #1
0
        public static Product CreateProduct(Product product)
        {
            using (var context = new ServicesContext())
            {
                // Check if product already exists within database.
                var findExistingProduct = context.Products.FirstOrDefault
                                              (b => b.productName.ToUpper() == product.productName.ToUpper());

                // Product object corrections
                product.productName        = product.productName.Trim();
                product.productDescription = product.productDescription.Trim();

                // Product doesn't exist.
                if (findExistingProduct == null)
                {
                    // Sum one to the counter of the product's category
                    var category = context.Categories.Single(b => b.ID == product.categoryID);
                    category.ammountProducts++;

                    context.Products.Add(product);
                    context.SaveChanges();

                    var newestProduct = context.Products.ToArray().Last();
                    return(newestProduct);
                }
                // Product already exists
                else
                {
                    return(null);
                }
            }
        }
        private async Task ClearWelcomeCommand(Message message, ServicesContext serviceContext, BotDbContext dbContext)
        {
            var client        = serviceContext.TelegramBotService.Client;
            var table         = dbContext.GroupMessages;
            var existingEntry = table.Where(welcome => welcome.ChatId == message.Chat.Id).FirstOrDefault();

            if (existingEntry != null)
            {
                await client.SendTextMessageAsync
                (
                    message.Chat.Id,
                    "Updated welcome message ^-^",
                    replyToMessageId : message.MessageId
                );

                table.Remove(existingEntry);
            }
            else
            {
                await client.SendTextMessageAsync
                (
                    message.Chat.Id,
                    "No welcome message anymore ^-^",
                    replyToMessageId : message.MessageId
                );
            }
            dbContext.SaveChanges();
        }
예제 #3
0
        private async Task WhoAmICommand(Message message, ServicesContext serviceContext, BotDbContext dbContext)
        {
            var client        = serviceContext.TelegramBotService.Client;
            var profilePhotos = await client.GetUserProfilePhotosAsync(message.From.Id, 0, 1);

            if (profilePhotos.TotalCount != 0)
            {
                await client.SendPhotoAsync
                (
                    message.Chat.Id,
                    profilePhotos.Photos[0][0].FileId,
                    $@"You are
<b>{message.From.FirstName} {message.From.LastName}{(message.From.IsBot ? "🤖" : "")}</b>
@{message.From.Username}
<code>{message.From.Id}</code>",
                    replyToMessageId : message.MessageId,
                    parseMode : ParseMode.Html
                );
            }
            else
            {
                await client.SendTextMessageAsync
                (
                    message.Chat.Id,
                    $@"You are
<b>{message.From.FirstName} {message.From.LastName}{(message.From.IsBot ? "🤖" : "")}</b>
@{message.From.Username}
<code>{message.From.Id}</code>",
                    replyToMessageId : message.MessageId,
                    parseMode : ParseMode.Html
                );
            }
        }
예제 #4
0
        public static Category CreateCategory(Category category)
        {
            using (var context = new ServicesContext())
            {
                // Check if category already exists within database.
                var findExistingCategory = context.Categories.FirstOrDefault
                                               (b => b.categoryName.ToUpper() == category.categoryName.ToUpper());

                // Category object corrections
                category.categoryName = category.categoryName.Trim();

                // Category doesn't exist.
                if (findExistingCategory == null)
                {
                    context.Categories.Add(category);
                    context.SaveChanges();

                    var newestCategory = context.Categories.ToArray().Last();
                    return(newestCategory);
                }
                // Category already exists
                else
                {
                    return(null);
                }
            }
        }
예제 #5
0
        public static Sale DeleteSale(int saleID)
        {
            using (var context = new ServicesContext())
            {
                var selectedSale = context.Sales.FirstOrDefault(b => b.ID == saleID);

                // Checking if the category exists within the database.
                if (selectedSale != null)
                {
                    // Minus one from the counter of the daily and monthly sale stats.
                    var selectedDailyStat   = context.dailyStats.FirstOrDefault(b => b.salesDate == selectedSale.saleDate);
                    var selectedMonthlyStat = context.monthlyStats.FirstOrDefault
                                                  (b => b.salesMonth == selectedSale.saleDate.Month && b.salesYear == selectedSale.saleDate.Year);

                    if (selectedDailyStat != null)
                    {
                        selectedDailyStat.productsSold--;
                    }
                    if (selectedMonthlyStat != null)
                    {
                        selectedMonthlyStat.productsSold--;
                    }

                    context.Sales.Remove(selectedSale);
                    context.SaveChanges();

                    return(selectedSale);
                }
                // If it does not, return null.
                else
                {
                    return(null);
                }
            }
        }
예제 #6
0
        private async Task RulesCommand(Message message, ServicesContext serviceContext, BotDbContext dbContext)
        {
            var client        = serviceContext.TelegramBotService.Client;
            var table         = dbContext.GroupMessages;
            var existingEntry = table.Where(welcome => welcome.ChatId == message.Chat.Id).FirstOrDefault();

            if (existingEntry != null)
            {
                await client.ForwardMessageAsync
                (
                    message.Chat.Id,
                    message.Chat.Id,
                    (int)existingEntry.RulesMessage
                );
            }
            else
            {
                await client.SendTextMessageAsync
                (
                    message.Chat.Id,
                    "No Rules Set",
                    replyToMessageId : message.MessageId
                );
            }
        }
예제 #7
0
        public static Product DeleteProduct(int productID)
        {
            using (var context = new ServicesContext())
            {
                var selectedProduct = context.Products.FirstOrDefault(b => b.ID == productID);

                // Checking if the category exists within the database.
                if (selectedProduct != null)
                {
                    // Minus one from the counter of the product's category.
                    var selectedCategory = context.Categories.FirstOrDefault(b => b.ID == selectedProduct.categoryID);
                    selectedCategory.ammountProducts--;

                    context.Products.Remove(selectedProduct);
                    context.SaveChanges();

                    return(selectedProduct);
                }
                // If it does not, return null.
                else
                {
                    return(null);
                }
            }
        }
        public static DailyStats DeleteDailyStat(int statID)
        {
            using (var context = new ServicesContext())
            {
                var selectedDailyStat = context.dailyStats.FirstOrDefault(b => b.ID == statID);

                // Checking if the daily stats exists within the database.
                if (selectedDailyStat != null)
                {
                    // Remove daily sales from the monthly stats counter.
                    var selectedMonthlyStat = context.monthlyStats.FirstOrDefault
                                                  (b => b.salesMonth == selectedDailyStat.salesDate.Month &&
                                                  b.salesYear == selectedDailyStat.salesDate.Year);

                    if (selectedMonthlyStat != null)
                    {
                        selectedMonthlyStat.productsSold -= selectedDailyStat.productsSold;
                    }

                    context.dailyStats.Remove(selectedDailyStat);
                    context.SaveChanges();

                    return(selectedDailyStat);
                }
                // If it does not, return null.
                else
                {
                    return(null);
                }
            }
        }
예제 #9
0
        public static JArray EliminarFactura(int facturaID)
        {
            JArray arrayJSON = BuscarFactura(facturaID);

            using (var context = new ServicesContext())
            {
                var factura = context.facturas.Where(x => x.ID == facturaID).
                              Select(x => new { x.ID, x.fecha, x.clienteFK }).FirstOrDefault();

                // La factura no existe, retornar nulo.
                if (factura == null)
                {
                    return(null);
                }
                else
                {
                    var encontrarFactura = context.facturas.SingleOrDefault(x => x.ID == facturaID);
                    context.facturas.Remove(encontrarFactura);
                    ServiciosDetallesFactura.RemoverDetallesFactura(facturaID);

                    context.SaveChanges();
                    return(arrayJSON);
                }
            }
        }
예제 #10
0
        public static Product UpdateProduct(int productID, Product product)
        {
            using (var context = new ServicesContext())
            {
                var selectedProduct = context.Products.FirstOrDefault(b => b.ID == productID);

                // Checking if the product does exist within the database.
                if (selectedProduct != null)
                {
                    // Update category counters if a new category has been set for the product.
                    if (selectedProduct.categoryID != product.categoryID)
                    {
                        var oldCategory = context.Categories.Single(b => b.ID == selectedProduct.categoryID);
                        oldCategory.ammountProducts--;
                        var newCategory = context.Categories.Single(b => b.ID == product.categoryID);
                        newCategory.ammountProducts++;
                    }

                    selectedProduct.categoryID         = product.categoryID;
                    selectedProduct.productName        = product.productName.Trim();
                    selectedProduct.productDescription = product.productDescription.Trim();
                    selectedProduct.productAmmount     = product.productAmmount;
                    selectedProduct.productPrice       = product.productPrice;
                    context.SaveChanges();

                    return(selectedProduct);
                }
                // If it does not, return null.
                else
                {
                    return(null);
                }
            }
        }
        public static Cliente CrearDetallesFactura(List <DetallesFactura> listaProductos)
        {
            using (var context = new ServicesContext())
            {
                if (listaProductos.Count > 0)
                {
                    context.BulkInsert(listaProductos);
                    int facturaID = listaProductos.FirstOrDefault().facturaFK;

                    int[] encontrarFKCliente = (from f in context.facturas
                                                join d in context.detallesFacturas on f.ID equals d.facturaFK where f.ID == facturaID
                                                select f.clienteFK
                                                ).ToArray();

                    int clienteID = encontrarFKCliente.First();

                    var datosCliente = (from c in context.clientes
                                        join f in context.facturas on c.ID equals f.clienteFK where c.ID == clienteID
                                        select new
                    {
                        c.ID,
                        c.nombreCliente,
                        c.RUT
                    }).FirstOrDefault();

                    Cliente infoCliente = new Cliente(datosCliente.ID, datosCliente.RUT, datosCliente.nombreCliente);
                    return(infoCliente);
                }
                else
                {
                    return(null);
                }
            }
        }
예제 #12
0
        private async Task ListAdminsCommand(Message message, ServicesContext serviceContext, BotDbContext dbContext)
        {
            var client = serviceContext.TelegramBotService.Client;
            var admins = await client.GetChatAdministratorsAsync(message.Chat.Id);

            var adminString = admins
                              .Select
                              (
                (admin) =>
                $@"• <b>{admin.User.FirstName} {admin.User.LastName}{(admin.User.IsBot ? "🤖" : "")}</b>
@{admin.User.Username}
<code>{admin.User.Id}</code>"
                              )
                              .Aggregate
                              (
                (s1, s2) => s1 + "\n\n" + s2
                              );
            await client.SendTextMessageAsync
            (
                message.Chat.Id,
                adminString,
                replyToMessageId : message.MessageId,
                parseMode : ParseMode.Html
            );
        }
 public static IEnumerable <DetallesFactura> BuscarDetallesFactura(int facturaID)
 {
     using (var context = new ServicesContext())
     {
         var listaDetalles = context.detallesFacturas.ToList().Where(x => x.facturaFK == facturaID);
         return(listaDetalles);
     }
 }
 public static MonthlyStats GetMonthlyStat(int id)
 {
     using (var context = new ServicesContext())
     {
         var monthlyStat = context.monthlyStats.FirstOrDefault(b => b.ID == id);
         return(monthlyStat);
     }
 }
 public static List <MonthlyStats> GetMonthlyStats()
 {
     using (var context = new ServicesContext())
     {
         var allMonthlyStats = context.monthlyStats.ToList();
         return(allMonthlyStats);
     }
 }
예제 #16
0
 public ServicesController(ServicesContext context, IResponce responce,
                           IConfiguration configuration, IImageHandler imageHandler)
 {
     _context       = context;
     _responce      = responce;
     _configuration = configuration;
     _imageHandler  = imageHandler;
 }
예제 #17
0
 public static List <DailyStats> GetDailyStats()
 {
     using (var context = new ServicesContext())
     {
         var allDailyStats = context.dailyStats.ToList();
         return(allDailyStats);
     }
 }
예제 #18
0
 public static Product GetProduct(int id)
 {
     using (var context = new ServicesContext())
     {
         var product = context.Products.FirstOrDefault(b => b.ID == id);
         return(product);
     }
 }
예제 #19
0
 public static List <Product> GetProduct()
 {
     using (var context = new ServicesContext())
     {
         var allProducts = context.Products.ToList();
         return(allProducts);
     }
 }
예제 #20
0
 public static Sale GetSale(int id)
 {
     using (var context = new ServicesContext())
     {
         var sale = context.Sales.FirstOrDefault(b => b.ID == id);
         return(sale);
     }
 }
예제 #21
0
 public static DailyStats GetDailyStat(int id)
 {
     using (var context = new ServicesContext())
     {
         var dailyStat = context.dailyStats.FirstOrDefault(b => b.ID == id);
         return(dailyStat);
     }
 }
예제 #22
0
 public static List <Sale> GetSales()
 {
     using (var context = new ServicesContext())
     {
         var allSales = context.Sales.ToList();
         return(allSales);
     }
 }
예제 #23
0
 public static Category GetCategory(int id)
 {
     using (var context = new ServicesContext())
     {
         var category = context.Categories.FirstOrDefault(b => b.ID == id);
         return(category);
     }
 }
예제 #24
0
 public static List <Category> GetCategory()
 {
     using (var context = new ServicesContext())
     {
         var allCategories = context.Categories.ToList();
         return(allCategories);
     }
 }
 public static Cliente BuscarCliente(int RUT)
 {
     using (var context = new ServicesContext())
     {
         var cliente = context.clientes.SingleOrDefault(x => x.RUT == RUT);
         return(cliente);
     }
 }
예제 #26
0
 //private UserManager<ServicesModel.Models.Auth.Auth> _manager;
 public AuthsController(ServicesContext context, IAutentication auth, IResponce responce,
                        IAccount account)
 {
     _context  = context;
     _auth     = auth;
     _responce = responce;
     _account  = account;
     // _manager = manager;
 }
        private async Task SaveMessage(Message message, ServicesContext serviceContext, BotDbContext dbContext)
        {
            var messageParts = message.Text.Split(' ');
            var client       = serviceContext.TelegramBotService.Client;

            if (messageParts.Length >= 2)
            {
                var originMessage = message.ReplyToMessage;
                if (originMessage == null)
                {
                    await client.SendTextMessageAsync
                    (
                        message.Chat.Id,
                        "Reply to a message >.> baka.",
                        replyToMessageId : message.MessageId
                    );
                }
                else
                {
                    var table         = dbContext.AdminSavedMessages;
                    var existingEntry = table.Where(savedMessage => savedMessage.ChatId == message.Chat.Id && savedMessage.MessageTag == messageParts[1]).FirstOrDefault();
                    if (existingEntry != null)
                    {
                        await client.SendTextMessageAsync
                        (
                            message.Chat.Id,
                            "Updated message ^-^",
                            replyToMessageId : message.MessageId
                        );

                        existingEntry.ChatId    = message.Chat.Id;
                        existingEntry.MessageId = originMessage.MessageId;
                    }
                    else
                    {
                        await client.SendTextMessageAsync
                        (
                            message.Chat.Id,
                            "Saved message ^-^",
                            replyToMessageId : message.MessageId
                        );

                        table.Add(new AdminSavedMessages(messageParts[1], message.Chat.Id, originMessage.MessageId));
                    }
                    await dbContext.SaveChangesAsync();
                }
            }
            else
            {
                await client.SendTextMessageAsync
                (
                    message.Chat.Id,
                    "Invalid request >_<",
                    replyToMessageId : message.MessageId
                );
            }
        }
예제 #28
0
 public MainContext()
 {
     Storage  = new StorageContext();
     Model    = new ModelContext(this);
     UI       = new UIContext(this);
     Security = new SecurityContext(this);
     Services = new ServicesContext(this);
     Settings = new SettingsContext();
 }
예제 #29
0
 public AccountsController(ServicesContext context,
                           IAccount account, IResponce responce, IImageHandler imageHandler, IConfiguration configuration)
 {
     _context       = context;
     _configuration = configuration;
     _account       = account;
     _responce      = responce;
     _imageHandler  = imageHandler;
 }
예제 #30
0
 public staffController(ServicesContext context, IResponce responce, IImageHandler imageHandler,
                        IAutentication auth, IConfiguration configuration)
 {
     _context       = context;
     _responce      = responce;
     _imageHandler  = imageHandler;
     _auth          = auth;
     _configuration = configuration;
 }