Esempio n. 1
0
        public bool Update(MoterBike motorBikeObj)
        {
            try
            {
                var query = (from motorBikes in dataContext.MoterBikes
                             where motorBikes.ProductID == motorBikeObj.ProductID
                             select motorBikes).First();
                query.ProductID       = motorBikeObj.ProductID;
                query.ProductName     = motorBikeObj.ProductName;
                query.Price           = motorBikeObj.Price;
                query.BrandName       = motorBikeObj.BrandName;
                query.Photo           = motorBikeObj.Photo;
                query.GroundClearance = motorBikeObj.GroundClearance;
                query.EngineCapacity  = motorBikeObj.EngineCapacity;
                query.Mileage         = motorBikeObj.Mileage;
                query.NoOfGears       = motorBikeObj.NoOfGears;
                query.TubelessTyres   = motorBikeObj.TubelessTyres;
                query.Weight          = motorBikeObj.Weight;
                query.CategoryID      = motorBikeObj.CategoryID;
                query.SubCategoryID   = motorBikeObj.SubCategoryID;

                int result = dataContext.SaveChanges();
            }
            catch (DbUpdateException ex)
            {
                dc.PCErrorLoggers.Add(new PCErrorLogger()
                {
                    ErrorDate    = DateTime.Now,
                    ErrorMessage = ex.Message,
                    ErrorSource  = ex.Source
                });
                dc.SaveChanges();
                throw new DbUpdateException("Please enter valid Foreign keys");
            }
            catch (System.FormatException fe)
            {
                dc.PCErrorLoggers.Add(new PCErrorLogger()
                {
                    ErrorDate    = DateTime.Now,
                    ErrorMessage = fe.Message,
                    ErrorSource  = fe.Source
                });
                dc.SaveChanges();
                throw new System.FormatException();
            }
            catch (Exception q)
            {
                dc.PCErrorLoggers.Add(new PCErrorLogger()
                {
                    ErrorDate    = DateTime.Now,
                    ErrorMessage = q.Message,
                    ErrorSource  = q.Source
                });
                dc.SaveChanges();
                throw new Exception("Incorrect Format");
            }
            return(true);
        }
Esempio n. 2
0
 public bool Insert(MoterBike motorBikeObj)
 {
     try
     {
         dataContext.MoterBikes.Add(motorBikeObj);
         int result = dataContext.SaveChanges();
     }
     catch (DbUpdateException ex)
     {
         dc.PCErrorLoggers.Add(new PCErrorLogger()
         {
             ErrorDate    = DateTime.Now,
             ErrorMessage = ex.Message,
             ErrorSource  = ex.Source
         });
         dc.SaveChanges();
         throw new DbUpdateException("Please enter valid Foreign keys");
     }
     catch (System.FormatException fe)
     {
         dc.PCErrorLoggers.Add(new PCErrorLogger()
         {
             ErrorDate    = DateTime.Now,
             ErrorMessage = fe.Message,
             ErrorSource  = fe.Source
         });
         dc.SaveChanges();
         throw new System.FormatException();
     }
     catch (Exception q)
     {
         dc.PCErrorLoggers.Add(new PCErrorLogger()
         {
             ErrorDate    = DateTime.Now,
             ErrorMessage = q.Message,
             ErrorSource  = q.Source
         });
         dc.SaveChanges();
         throw new Exception("Incorrect Format");
     }
     return(true);
 }