public void InsertLog(BackupLog log) { using (var ctx = new LANBackupContext()) { var dbLog = new BACKUPLOG { ID = log.Id, BACKUPJOBID = log.BackupJobId, MESSAGE = log.Message }; ctx.BACKUPLOGs.Add(dbLog); ctx.SaveChanges(); } }
private void CreateClient(Client client) { using (var ctx = new LANBackupContext()) { var dbclient = ctx.CLIENTs.FirstOrDefault(p => p.CLIENTID == client.ClientId); if (dbclient != null) { dbclient.ISAVAILABLE = client.isAvailable; ctx.SaveChanges(); } else { dbclient = new CLIENT { CLIENTID = client.ClientId, ISAVAILABLE = client.isAvailable }; ctx.CLIENTs.Add(dbclient); ctx.SaveChanges(); } } }
private void CreateUser(User user) { using (var ctx = new LANBackupContext()) { var dbuser=ctx.USERS.FirstOrDefault(p => p.USERID == user.UserId); if (dbuser != null) { dbuser.PASSWORD = user.Password; dbuser.DOMAIN = user.Domain; ctx.SaveChanges(); } else { dbuser = new USER { USERID = user.UserId, PASSWORD = user.Password, DOMAIN = user.Domain }; ctx.USERS.Add(dbuser); ctx.SaveChanges(); } } }
public void CreateBackupJob(BackupJob job) { CreateUser(job.SourceUser); CreateUser(job.DestinationUser); CreateClient(job.Client); using (var ctx = new LANBackupContext()) { var dbJob = MapToDbBackupJob(job); ctx.BACKUPJOBS.Add(dbJob); ctx.SaveChanges(); } }
public void UpdateBackupJobStatus(Guid backupJobId, JobStatus status) { using (var ctx = new LANBackupContext()) { var job = ctx.BACKUPJOBS.FirstOrDefault(p => p.ID == backupJobId); if (job != null) { job.STATUS = (int) status; ctx.SaveChanges(); } } }
public void DeleteBackupJob(Guid Id) { using (var ctx = new LANBackupContext()) { var job = ctx.BACKUPJOBS.FirstOrDefault(p => p.ID == Id); var log = ctx.BACKUPLOGs.FirstOrDefault(p => p.BACKUPJOBID == job.ID); if (log != null) throw new Exception("Deleting already run job is not allowed"); if (job != null) { ctx.BACKUPJOBS.Remove(job); ctx.SaveChanges(); } } }
public void EnableBackupJob(Guid Id, bool isEnable) { using (var ctx = new LANBackupContext()) { var job = ctx.BACKUPJOBS.FirstOrDefault(p => p.ID == Id); if (job != null) { job.ISENABLED = isEnable; ctx.SaveChanges(); } } }
public void EditBackupJob(BackupJob job) { using (var ctx = new LANBackupContext()) { var editJob = ctx.BACKUPJOBS.FirstOrDefault(p => p.ID == job.Id); var log = ctx.BACKUPLOGs.FirstOrDefault(p => p.ID == job.Id); if (log != null) throw new Exception("Editing on already run job is not Allowed"); if (editJob != null) { var dbJob = MapToDbBackupJob(job); ctx.BACKUPJOBS.Remove(editJob); ctx.BACKUPJOBS.Add(dbJob); ctx.SaveChanges(); } } }