public static int createFamily(tblFamily c) { var res = -1; try { using (var db = new BusProjectEntities()) { var pid = 0; int.TryParse(db.tblFamilies.Max(z => z.ParentId), out pid); c.ParentId = (pid + 1).ToString(); c.date = DateTime.Today; c.LastUpdate = DateTime.Today; c.registrationStatus = false; db.tblFamilies.Add(c); db.SaveChanges(); res = c.familyId; } } catch (DbEntityValidationException ex) { var e = ex.EntityValidationErrors.FirstOrDefault(); throw; } return(res); }
public static void updateSystemValueByKey(tblSystem c) { try { BusProjectEntities db = new BusProjectEntities(); db.Entry <tblSystem>(c).State = EntityState.Modified; db.SaveChanges(); } catch { } }
//Todo- get from tblsystemConterol the current culture public static void addTblDict(tblDictSystem c) { try { BusProjectEntities db = new BusProjectEntities(); db.tblDictSystems.Add(c); db.SaveChanges(); } catch { } }
public static void addEmailSent(tblEmailSent c) { try { BusProjectEntities db = new BusProjectEntities(); db.tblEmailSents.Add(c); db.SaveChanges(); } catch { } }
public static void update(tblFamily c) { try { BusProjectEntities db = new BusProjectEntities(); db.Entry <tblFamily>(c).State = EntityState.Modified; db.SaveChanges(); } catch { } }
public static void update(tblStudent c) { try { var db = new BusProjectEntities(); db.Entry <tblStudent>(c).State = EntityState.Modified; db.SaveChanges(); } catch (DbEntityValidationException ex) { var s = ex.EntityValidationErrors.ToList(); } }
public static void deleteTblDict(int id) { try { BusProjectEntities db = new BusProjectEntities(); db.Entry <tblDictSystem>(new tblDictSystem { id = id }).State = EntityState.Deleted; db.SaveChanges(); } catch { } }
public tblCalendar SaveEvent(tblCalendar calendarEvent) { try { BusProjectEntities db = new BusProjectEntities(); db.tblCalendars.Add(calendarEvent); db.SaveChanges(); return(calendarEvent); } catch (Exception ex) { Console.WriteLine(ex); } return(null); }
public Bus SaveBus(Bus bus) { try { BusProjectEntities db = new BusProjectEntities(); db.Buses.Add(bus); db.SaveChanges(); return(bus); } catch (Exception ex) { Console.WriteLine(ex); } return(null); }
public Line SaveLine(Line line) { line.CssToNumeric(); try { BusProjectEntities db = new BusProjectEntities(); db.Lines.Add(line); db.SaveChanges(); return(line); } catch (Exception ex) { Console.WriteLine(ex); } return(null); }
public static void updateFamilyId(string userName, int familyId) { try { BusProjectEntities db = new BusProjectEntities(); var c = (from s in db.Logins where (s.userName == userName) select s).FirstOrDefault(); c.familyId = familyId; db.SaveChanges(); } catch (Exception ex) {//todo write to log throw ex; } }
public bool Update(tblCalendar calendarEvent) { var res = false; try { BusProjectEntities db = new BusProjectEntities(); db.Entry(calendarEvent).State = EntityState.Modified; db.SaveChanges(); res = true; } catch (Exception ex) { Console.WriteLine(ex); } return(res); }
public static bool confirmEmail(string userName) { try { BusProjectEntities db = new BusProjectEntities(); var c = (from s in db.Logins where (s.userName == userName) select s).FirstOrDefault(); c.emailConfirm = true; db.SaveChanges(); return(true); } catch { return(false); } }
public bool Update(tblSchedule scheduleItem) { var res = false; try { UpdateLineBus(scheduleItem.LineId, scheduleItem.BusId); BusProjectEntities db = new BusProjectEntities(); db.Entry(scheduleItem).State = EntityState.Modified; db.SaveChanges(); res = true; } catch (Exception ex) { Console.WriteLine(ex); } return(res); }
public bool Update(Line line) { line.CssToNumeric(); var res = false; try { BusProjectEntities db = new BusProjectEntities(); db.Entry(line).State = EntityState.Modified; db.SaveChanges(); res = true; } catch (Exception ex) { Console.WriteLine(ex); } return(res); }
public static void create(tblStudent c) { try { BusProjectEntities db = new BusProjectEntities(); var ids = db.tblStudents.Select(z => z.studentId).ToList(); var pid = ids.Max(z => Int32.Parse(z)) + 1; c.studentId = pid.ToString(); c.dateCreate = DateTime.Today; c.lastUpdate = DateTime.Today; var crYear = tblSystemLogic.getSystemValueByKey("currentRegistrationYear"); c.yearRegistration = crYear == null ? DateTime.Now.Year : int.Parse(crYear.strValue); c.registrationStatus = false; db.tblStudents.Add(c); db.SaveChanges(); } //sqlException catch (DbEntityValidationException ex) { foreach (DbEntityValidationResult item in ex.EntityValidationErrors) { // Get entry DbEntityEntry entry = item.Entry; string entityTypeName = entry.Entity.GetType().Name; // Display or log error messages foreach (DbValidationError subItem in item.ValidationErrors) { string message = string.Format("Error '{0}' occurred in {1} at {2}", subItem.ErrorMessage, entityTypeName, subItem.PropertyName); //Console.WriteLine(message); } } } //catch (DbUpdateException ex) //{ // var sqlex = ex.InnerException.InnerException as SqlException; // if (sqlex != null) // { // switch (sqlex.Number) // { // case 547: throw new ExNoExisteUsuario("No existe usuario destino."); //FK exception // case 2627: // case 2601: // throw new ExYaExisteConexion("Ya existe la conexion."); //primary key exception // default: throw sqlex; //otra excepcion que no controlo. // } // } // throw ex; //} }