Exemplo n.º 1
0
 public static bool ModifyHangar(string id, int N, out bool success, out string exceptionString)
 {
     try
     {
         using (WarehouseContext db = new WarehouseContext())
         {
             bool   exist, hSuccess;
             string hExcStr;
             Hangar hangar = GetHangar(id, out exist, out hSuccess, out hExcStr);
             if (!hSuccess)
             {
                 success         = false;
                 exceptionString = hExcStr;
                 return(false);
             }
             success         = true;
             exceptionString = null;
             if (exist)
             {
                 int newFullness = hangar.fullness + N;
                 if (newFullness >= 0 && newFullness <= hangar.capacity)
                 {
                     db.hangars.FirstOrDefault(e => e.id == id).fullness = newFullness;
                     if (db.sites.Any(e => e.id == hangar.site_id))
                     {
                         db.sites.FirstOrDefault(e => e.id == hangar.site_id).capacity -= N;
                         if (newFullness == 0)
                         {
                             if (!db.hangars.Any(e => e.site_id == id && e.fullness > 0))
                             {
                                 db.sites.FirstOrDefault(e => e.id == hangar.site_id).empty = true;
                             }
                         }
                         else if (db.sites.FirstOrDefault(e => e.id == hangar.site_id).empty)
                         {
                             db.sites.FirstOrDefault(e => e.id == hangar.site_id).empty = false;
                         }
                     }
                     db.SaveChanges();
                     return(true);
                 }
             }
             return(false);
         }
     }
     catch (Exception e)
     {
         ExceptionLogger.Instance.LogException(e.ToString(), DateTime.UtcNow);
         success         = false;
         exceptionString = e.ToString();
         return(false);
     }
 }
Exemplo n.º 2
0
        public static void CreateSeedData()
        {
            using (var db = new WarehouseContext())
            {
                foreach (var stockItem in Initial.Data())
                {
                    db.StockItems.Add(stockItem);
                }

                db.SaveChanges();
            }
        }
Exemplo n.º 3
0
 public void SaveChanges()
 {
     _context.SaveChanges();
 }