Example #1
0
        public void deleteAllBookingLineForBooking(int bookingid)
        {
            using (ElectricCarEntities context = new ElectricCarEntities())
            {
                try
                {
                    BookingLine[] blsToDelete;
                    var items = from item in context.BookingLines where item.bId == bookingid select item;
                    blsToDelete = items.ToArray<BookingLine>();

                    if (blsToDelete != null)
                    {
                        foreach (BookingLine item in blsToDelete)
                        {
                            context.Entry(item).State = EntityState.Deleted;
                        }

                    }
                    context.SaveChanges();
                }
                catch (Exception)
                {

                    throw new System.NullReferenceException("Can not find booking line");
                }
            }
        }
Example #2
0
 public void deleteRecord(int id1, int id2)
 {
     using (ElectricCarEntities context = new ElectricCarEntities())
     {
         Connection conToDelete = context.Connections.Find(id1, id2);
         if (conToDelete != null)
         {
             context.Entry(conToDelete).State = EntityState.Deleted;
             context.SaveChanges();
         }
         else
         {
             throw new System.NullReferenceException("Can not find nabor station");
         }
     }
 }
Example #3
0
 public void deleteRecord(int bsID)
 {
     using (ElectricCarEntities context = new ElectricCarEntities())
     {
         Period perToDelete = context.Period.Find(bsID);
         if (perToDelete != null)
         {
             context.Entry(perToDelete).State = EntityState.Deleted;
             context.SaveChanges();
         }
         else
         {
             throw new System.NullReferenceException("Can not find period");
             //throw new SystemException("Can not find period");
         }
     }
 }
Example #4
0
 public void deleteRecord(int id)
 {
     using (ElectricCarEntities context = new ElectricCarEntities())
     {
         BatteryStorage storToDelete = context.BatteryStorage.Find(id);
         if (storToDelete != null)
         {
             context.Entry(storToDelete).State = EntityState.Deleted;
             context.SaveChanges();
         }
         else
         {
             throw new System.NullReferenceException("Can not find battery storage");
             //throw new SystemException("Can not find battery storage");
         }
     }
 }
Example #5
0
        public void deleteRecord(int id)
        {
            using (ElectricCarEntities context = new ElectricCarEntities())
            {
                try
                {
                    Station staToDelete = context.Stations.Find(id);
                    if (staToDelete != null)
                    {
                        context.Entry(staToDelete).State = EntityState.Deleted;
                        context.SaveChanges();
                    }
                }
                catch (Exception)
                {
                    throw new System.NullReferenceException("Can not find nabor station");
                }

            }
        }
Example #6
0
 public void deleteRecord(int id)
 {
     using (TransactionScope transaction = new TransactionScope((TransactionScopeOption.Required)))
     {
         try
         {
             using (ElectricCarEntities context = new ElectricCarEntities())
             {
                 try
                 {
                     DiscoutGroup dg = context.DiscoutGroups.Find(id);
                     if (dg != null)
                     {
                         context.Entry(dg).State = EntityState.Deleted;
                         context.SaveChanges();
                     }
                 }
                 catch (Exception e)
                 {
                     throw new SystemException("Cannot delete Discount Group " + id + " record " +
                         " with an error " + e.Message);
                 }
             }
             transaction.Complete();
         }
         catch (TransactionAbortedException e)
         {
             throw new SystemException("Cannot finish transaction for deleting Discount Group " +
                " with an error " + e.Message);
         }
     }
 }
Example #7
0
        public void deleteRecord(int id)
        {
            using (ElectricCarEntities context = new ElectricCarEntities())
            {
                try
                {
                bool success = false;
                using(TransactionScope scope = new TransactionScope())
                {
                    try
                    {
                         BatteryType btToDelete = context.BatteryTypes.Find(id);

                                context.Entry(btToDelete).State = EntityState.Deleted;
                                context.SaveChanges();
                                success = true;
                     }
                        catch(Exception)
                        {
                            throw new System.NullReferenceException("Can not find battery type");
                            //throw new SystemException("Can not find battery type");
                        }
                        if (success)
                        {
                            scope.Complete();
                        }

                    }
                }
                    catch (TransactionAbortedException e)
                    {
                        throw new SystemException("Cannot finish transaction for deleting BatteryType " +
                           " with an error " + e.Message);
                    }
                }
        }
Example #8
0
        public void deleteRecordByType(int btID)
        {
            using (ElectricCarEntities context = new ElectricCarEntities())
            {
                try
                {
                    bool success = false;
                    using (TransactionScope scope = new TransactionScope())
                    {
                        try
                        {
                            BatteryStorage storToDelete = (BatteryStorage) context.BatteryStorages.Where(bt=>btID==bt.btId).FirstOrDefault();
                            context.Entry(storToDelete).State = EntityState.Deleted;
                            context.SaveChanges();
                            success = true;
                        }
                        catch (Exception)
                        {
                            throw new System.NullReferenceException("Can not delete battery storage. Delete battery type first.");
                            //throw new SystemException("Can not find battery type");
                        }
                        if (success)
                        {
                            scope.Complete();
                        }

                    }
                }
                catch (TransactionAbortedException e)
                {
                    throw new SystemException("Cannot finish transaction for deleting BatteryType " +
                       " with an error " + e.Message);
                }
            }
        }
Example #9
0
        public void deleteRecord(int bId, int btId, int sId)
        {
            using (ElectricCarEntities context = new ElectricCarEntities())
            {
                try
                {
                    BookingLine blToDelete = context.BookingLines.Find(bId, btId, sId);
                    if (blToDelete != null)
                    {
                        context.Entry(blToDelete).State = EntityState.Deleted;
                        context.SaveChanges();
                    }
                }
                catch (Exception)
                {

                    throw new System.NullReferenceException("Can not find booking line");
                }
            }
        }
Example #10
0
 public void deleteRecord(int id)
 {
     using (TransactionScope transaction = new TransactionScope((TransactionScopeOption.Required)))
     {
         try
         {
             using (ElectricCarEntities context = new ElectricCarEntities())
             {
                 try
                 {
                     Person emp = context.People.Find(id);
                     IEnumerable<LoginInfo> logInfos = context.LoginInfoes.Where(pid => pid.pId == emp.Id);
                     if (emp != null)
                     {
                         context.Entry(emp).State = EntityState.Deleted;
                         // delete all associated logInfos
                         foreach (LoginInfo logInfo in logInfos)
                         {
                             context.Entry(logInfo).State = EntityState.Deleted;
                         }
                         context.SaveChanges();
                     }
                 }
                 catch (Exception e)
                 {
                     throw new SystemException("Cannot delete Employee " + id + " record "
                         + " with message " + e.Message);
                 }
             }
             transaction.Complete();
         }
         catch (TransactionAbortedException e)
         {
             throw new SystemException("Cannot finish transaction for deleting Employee no. " + id +
                 " with an error " + e.Message);
         }
     }
 }
Example #11
0
        public void deleteRecord(int bsID)
        {
            using (ElectricCarEntities context = new ElectricCarEntities())
            {
                try
                {
                    bool success = false;
                    using (TransactionScope scope = new TransactionScope())
                    {
                        try
                        {
                            do
                            {
                                context.Entry(context.Periods.Where(bs => bs.bsId == bsID).FirstOrDefault()).State = EntityState.Deleted;
                                context.SaveChanges();
                            }
                            while (context.Periods.Where(bs => bs.bsId == bsID).Count() != 0);

                            success = true;
                        }
                        catch (Exception)
                        {
                            throw new System.NullReferenceException("Can not find battery type");
                            //throw new SystemException("Can not find battery type");
                        }
                        if (success)
                        {
                            scope.Complete();
                        }

                    }
                }
                catch (TransactionAbortedException e)
                {
                    throw new SystemException("Cannot finish transaction for deleting BatteryType " +
                       " with an error " + e.Message);
                }
            }
        }