public static void Add(Log log)
        {
            var db = new SoftwareStudioContext();

            if (log != null)
            {
                db.logs.Add(log);
                db.SaveChanges();
            }
        }
        public static void AddWithTransaction(Transaction transaction)
        {
            var db = new SoftwareStudioContext();

            if (transaction != null)
            {
                db.logs.Add(new Log(transaction));
                db.SaveChanges();
            }
        }
        public static void Remove(Item item)
        {
            var db = new SoftwareStudioContext();

            if (item != null)
            {
                db.Remove(item);
                db.SaveChanges();
            }
        }
Beispiel #4
0
        public static async void RemoveItem(int itemID)
        {
            var             db      = new SoftwareStudioContext();
            Laboratory_item labItem = await db.laboratory_items.FirstOrDefaultAsync(labItem => labItem.item_id == itemID);

            if (labItem != null)
            {
                db.Remove(labItem);
                db.SaveChanges();
            }
        }
Beispiel #5
0
        public static void AddItem(int labID, int itemID)
        {
            var             db      = new SoftwareStudioContext();
            Laboratory_item labItem = new Laboratory_item(labID, itemID);

            if (labItem != null)
            {
                db.laboratory_items.Add(labItem);
                db.SaveChanges();
            }
        }
Beispiel #6
0
        public static void Cancel(Transaction transaction)
        {
            var db = new SoftwareStudioContext();

            if (transaction != null)
            {
                var temp = db.transactions.Remove(transaction);;
                transaction.transaction_type = (int)Transaction_type.cancel;
                db.logs.Add(new Log(transaction));
                db.SaveChanges();
            }
        }
Beispiel #7
0
        public static void Delete(Transaction transaction)
        {
            var db = new SoftwareStudioContext();

            if (transaction != null)
            {
                db.transactions.Remove(transaction);
                transaction.transaction_type = (int)Transaction_type.give;
                db.logs.Add(new Log(transaction));
                db.SaveChanges();
            }
        }
Beispiel #8
0
        public static int Register(User user)
        {
            Console.WriteLine("user {0}", user);
            var db = new SoftwareStudioContext();

            /// hash password.
            string hashedPassword = BCrypt.Net.BCrypt.HashPassword(user.password);

            user.password = hashedPassword;
            db.users.Add(user);
            db.SaveChanges();

            return(0);
        }
        public static int Add(Item item)
        {
            var db = new SoftwareStudioContext();

            if (item != null)
            {
                var change = db.items.Add(item);
                db.SaveChanges();

                return(change.Entity.uuid);
            }
            else
            {
                return(-1);
            }
        }
Beispiel #10
0
        public static async Task <int> Add(Transaction transaction)
        {
            var db = new SoftwareStudioContext();

            DateTime datetime_now = DateTime.Now;

            int hour;

            if (transaction.time_id == (int)Time_id_type.PM)
            {
                hour = 12;
            }
            else
            {
                hour = 8;
            }
            DateTime book_date = new DateTime(transaction.book_date.Year,
                                              transaction.book_date.Month,
                                              transaction.book_date.Day,
                                              hour, 0, 0);

            string             query_string = $@"SELECT * FROM transactions 
                                        WHERE book_date = '{book_date.ToString("yyyy-MM-dd")}'
                                        and (time_id = {transaction.time_id} or time_id={(int)Time_id_type.Day})
                                        and (item_id = {transaction.item_id})";
            List <Transaction> t            = await db.transactions.FromSqlRaw(query_string).ToListAsync();

            if (t.Count > 0)
            {
                return(1);
            }
            int result = DateTime.Compare(datetime_now, book_date);

            if (result <= 0)
            {
                db.transactions.Add(transaction);
                db.logs.Add(new Log(transaction));
                db.SaveChanges();
                return(0);
            }
            return(1);
        }