示例#1
0
        public bool BorrowDevice(string deviceNO, string borrowBy, string submitter)
        {
            using (var db = new EWContext(EWContext.connStr))
            {
                using (var dbcxtransaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        db.Devices.First(x => x.NO == deviceNO).Status = DeviceStatus.Lent;
                        db.SaveChanges();

                        db.DeviceBorrows.Add(new DeviceBorrow()
                        {
                            DeviceNO  = deviceNO,
                            BorrowBy  = borrowBy,
                            Submitter = submitter,
                            Date      = DateTime.Now
                        });
                        db.SaveChanges();
                        dbcxtransaction.Commit();
                        return(true);
                    }
                    catch (Exception ex)
                    {
                        dbcxtransaction.Rollback();
                        Log.Instance.Logger.Error(ex.Message);
                        return(false);
                    }
                }
            }
        }
示例#2
0
 public bool AddDevice(int category2Id, int quantity)
 {
     try
     {
         using (var db = new EWContext(EWContext.connStr))
         {
             //int cat1Id = db.Category2s.Include(nameof(Category1))
             //    .First(x => x.Id == category2Id).Category1.Id;
             for (int i = 1; i <= quantity; i++)
             {
                 db.Devices.Add(new Device()
                 {
                     NO          = $"{category2Id}-{i}",
                     Category2Id = category2Id,
                     Status      = DeviceStatus.Instore,
                     InStoreDate = DateTime.Now
                 });
             }
             db.SaveChanges();
         }
         return(true);
     }
     catch (Exception ex)
     {
         Log.Instance.Logger.Error(ex.Message);
         return(false);
     }
 }
示例#3
0
 public IList <Device> GetAllDevices()
 {
     try
     {
         using (var db = new EWContext(EWContext.connStr))
         {
             return(db.Devices.ToList());
         }
     }
     catch (Exception ex)
     {
         Log.Instance.Logger.Error(ex.Message);
         return(new List <Device>());
     }
 }
示例#4
0
 public bool AddCategory2(int category1Id, string name)
 {
     try
     {
         using (var db = new EWContext(EWContext.connStr))
         {
             db.Category2s.Add(new Category2()
             {
                 Category1Id = category1Id, Name = name
             });
             db.SaveChanges();
         }
         return(true);
     }
     catch (Exception ex)
     {
         Log.Instance.Logger.Error(ex.Message);
         return(false);
     }
 }