public bool SaveWorkstation(Models.Workstation.Workstation workstation, int userId) { using (var context = GetContext()) { try { if (!context.Workstations.Where(x => x.Regular_UserId == userId).Any(x => x.Name.ToLower() == workstation.Name.ToLower())) { var workstationId = context.Workstations.Any() ? context.Workstations.Max(x => x.WorkstationId) + 1 : 1; workstation.CreationDate = DateTime.Now.Date; context.Workstations.Add(new DataBase.Workstation { WorkstationId = workstationId, Regular_UserId = userId, CreationDate = workstation.CreationDate, Name = workstation.Name, }); context.SaveChanges(); workstation.WorkstationId = workstationId; return(true); } } catch (System.Exception) { } } return(false); }
public void RemoveWorkstation(Models.Workstation.Workstation workstation) { using (var context = GetContext()) { try { var workstationDB = context.Workstations.Where(x => x.WorkstationId == workstation.WorkstationId).Single(); context.Workstations.Remove(workstationDB); context.SaveChanges(); } catch (System.Exception) { } } }