public void Delete(actor ator) { using (var db = new SakilaContext()) //Como não há concorrência nas modificações, não é necessário criar um contexto transacional. //using (var transacao = db.Database.BeginTransaction()) { try { db.films_actors.RemoveRange(ator.films_actors); db.actors.Remove(ator); db.SaveChanges(); //transacao.Commit(); } catch { //transacao.Rollback(); //tratar exceção e gravar no log além de fechar a transação throw; } /* finally * { * transacao.Dispose(); * }; */ } }
//MicroService 5 public IActionResult ReadMQ3ServicePointNWriteToDB() { try { //Read from MQ //ServicePoint servicePointObject = CommonUtility<ServicePoint>.PullFromActiveMQ(3); var spProcString = Request.Headers["servicePointString"]; ServicePoint servicePointObject = Newtonsoft.Json.JsonConvert.DeserializeObject <ServicePoint>(spProcString); //Write Servicepoint to DB SakilaContext context = HttpContext.RequestServices.GetService(typeof(SakilaContext)) as SakilaContext; context.AddNewServicePoint(servicePointObject); log.Info(DateTime.Now.ToString() + " AMS-POC: Service point inserted in to database."); } catch (Exception ex) { log.Error(DateTime.Now.ToString() + " AMS-POC: " + Convert.ToString(ex.Message)); return(new JsonResult(new { Result = System.Net.HttpStatusCode.InternalServerError })); } return(Ok()); }
//MicroService 4 public IActionResult ReadMQ2OPLDNCreateSPNPushTOMQ3() { try { //Read from MQ OPLD opldObject = CommonUtility <OPLD> .PullFromActiveMQ(2); ServicePoint servicePointObject = new ServicePoint(); //CreateServicepoint //Check if opld tracking number matches with dials matching number SakilaContext context = HttpContext.RequestServices.GetService(typeof(SakilaContext)) as SakilaContext; DIALS dialsObject = context.GetMatchingDialsID(opldObject.TrackingNumber); if (dialsObject != null) { servicePointObject = ServicePointUtility.CreateServicePoint(opldObject, dialsObject.ConsigneeName, dialsObject.ClarifiedSignature, true); } else { servicePointObject = ServicePointUtility.CreateServicePoint(opldObject, "", "", false); } //Push OPLD in to Active MQ2 CommonUtility <ServicePoint> .PushToActiveMQ(servicePointObject, 3); } catch { return(new JsonResult(new { Result = System.Net.HttpStatusCode.InternalServerError })); } return(Ok()); }
public IActionResult MicroServiceProcessOPLDFile(List <OPLD> opldObjectList) { try { //Push OPLD in DB SakilaContext context = new SakilaContext("server=127.0.01;port=3306;database=ams;user=root;password=techM@Ups1"); //SakilaContext context = new SakilaContext("server=techm.cooavdyjxzoz.us-east-1.rds.amazonaws.com;port=3306;database=ams;user=root;password=Password123"); foreach (var opldObject in opldObjectList) { var addOPLDResult = context.AddNewOPLD(opldObject); if (addOPLDResult.Item1) { opldObject.Packages.ForEach(m => m.OPLDId = addOPLDResult.Item2); context.AddNewOPLDPackages(opldObject.Packages); } } log.Info(DateTime.Now.ToString() + " AMS-POC-MicroServiceProcessOPLDNDIALSFiles: OPLD Data inserted in DB."); //Push OPLD in to Active MQ2 CommonUtility <OPLD> .PushToActiveMQ(opldObjectList, 1); log.Info(DateTime.Now.ToString() + " AMS-MicroServiceProcessOPLDNDIALSFiles: OPLD message pushed to MQ."); } catch (Exception ex) { log.Error(DateTime.Now.ToString() + " AMS-MicroServiceProcessOPLDNDIALSFiles: " + Convert.ToString(ex.Message)); return(new JsonResult(new { Result = System.Net.HttpStatusCode.InternalServerError })); } return(Ok(new { Result = "Success" })); }
//MicroService 2 public IActionResult ProcessMQ1OPLDMessageNWriteToDBNMQ2() { try { //Read from MQ OPLD opldObject = CommonUtility <OPLD> .PullFromActiveMQ(1); log.Info(DateTime.Now.ToString() + " AMS-POC: OPLD message read from MQ1."); //Store in to DB SakilaContext context = HttpContext.RequestServices.GetService(typeof(SakilaContext)) as SakilaContext; context.AddNewOPLD(opldObject); log.Info(DateTime.Now.ToString() + " AMS-POC: OPLD message inserted in to database."); //Push OPLD in to Active MQ2 CommonUtility <OPLD> .PushToActiveMQ(opldObject, 2); log.Info(DateTime.Now.ToString() + " AMS-POC: OPLD message pushed to MQ2."); } catch (Exception ex) { log.Error(DateTime.Now.ToString() + " AMS-POC: " + Convert.ToString(ex.Message)); return(new JsonResult(new { Result = System.Net.HttpStatusCode.InternalServerError })); } return(Ok()); }
public void Insert(actor ator) { using (var db = new SakilaContext()) { db.actors.Add(ator); db.SaveChanges(); } }
public void Update(actor ator) { using (var db = new SakilaContext()) { db.actors.Update(ator); db.SaveChanges(); } }
public void Incluir(film filme) { using (var db = new SakilaContext()) { db.films.Add(filme); db.SaveChanges(); } }
public void OPLDFileWatcher() { try { var opldFolderPath = Path.Combine(Directory.GetCurrentDirectory(), "OPLDFiles"); var files = Directory.GetFiles(opldFolderPath); if (files.Length > 0) { foreach (string fileName in files) { log.Info(DateTime.Now.ToString() + " AMS-POC-MicroServiceProcessOPLDNDIALSFiles: OPLD file Read in Progress."); string opldString = System.IO.File.ReadAllText(Path.Combine(opldFolderPath, fileName)); //Process OPLD data var opldObject = OPLDUtility.ProcessOPLD(opldString); //Check is File already Processed //SakilaContext context = new SakilaContext("server=127.0.01;port=3306;database=ams;user=root;password=techM@Ups1"); SakilaContext context = new SakilaContext("server=techm.cooavdyjxzoz.us-east-1.rds.amazonaws.com;port=3306;database=sakila;user=root;password=Password123"); //bool trackResult = context.CheckIsTrackingNumberAlreadyExists(opldObject.TrackingNumber); //if (trackResult) //{ // log.Info(DateTime.Now.ToString() + " AMS-POC-MicroServiceProcessOPLDNDIALSFiles: OPLD file Read already processed."); // continue; //} log.Info(DateTime.Now.ToString() + " AMS-POC-MicroServiceProcessOPLDNDIALSFiles: OPLD file Processed."); //Push OPLD to Queue MicroServiceProcessOPLDFile(opldObject); log.Info(DateTime.Now.ToString() + " AMS-POC-MicroServiceProcessOPLDNDIALSFiles: OPLD Message Pushed to MQ."); var archiveFolderPath = Path.Combine(Directory.GetCurrentDirectory(), "Archive"); DirectoryInfo directoryInfo = Directory.CreateDirectory(archiveFolderPath); if (!System.IO.File.Exists(archiveFolderPath + fileName.Substring(fileName.LastIndexOf("\\")))) { System.IO.File.Move(fileName, archiveFolderPath + fileName.Substring(fileName.LastIndexOf("\\"))); } else { System.IO.File.Delete(fileName); } } } } catch (Exception ex) { log.Error(DateTime.Now.ToString() + " AMS-MicroServiceProcessOPLDNDIALSFiles: " + Convert.ToString(ex.Message)); } }
public actor ObterPorSobrenome(string sobrenome) { actor ator = null; using (var db = new SakilaContext()) { ator = db.actors.FirstOrDefault(x => x.last_name.Contains(sobrenome)); } return(ator); }
public actor GetById(int?primarykey) { actor ator = null; using (var db = new SakilaContext()) { ator = ObterPorId(db, primarykey.Value); } return(ator); }
//MicroService 3 public async Task <IActionResult> ProcessDIALSDataNWriteToDB() { try { string dialsFolderPath = Path.Combine(Directory.GetCurrentDirectory(), "DIALSFiles"); if (Directory.Exists(dialsFolderPath)) { var files = Directory.GetFiles(dialsFolderPath); if (files.Length > 0) { foreach (string fileName in files) { log.Info(DateTime.Now.ToString() + " AMS-POC: DIALS file processing in progress - " + fileName); FileStream fileStream = new FileStream(Path.Combine(dialsFolderPath, fileName), FileMode.Open); using (BufferedStream bufferedStream = new BufferedStream(fileStream)) { using (StreamReader streamReader = new StreamReader(bufferedStream)) { while (!streamReader.EndOfStream) { string dialsString = await streamReader.ReadLineAsync(); //Process DIALS data var dialsObject = DIALSUtility.ProcessDIALSData(dialsString); //Store in to DB if (!string.IsNullOrEmpty(dialsObject.TrackingNumber)) { SakilaContext context = HttpContext.RequestServices.GetService(typeof(SakilaContext)) as SakilaContext; context.AddNewDIALS(dialsObject); } else { log.Warn(DateTime.Now.ToString() + " AMS-POC: Tracking number not found in DIALS data."); } } } } log.Info(DateTime.Now.ToString() + " AMS-POC: DIALS file processing completed - " + fileName); } log.Info(DateTime.Now.ToString() + " AMS-POC: Total DIALS files processed - " + files.Length); } } } catch (Exception ex) { log.Error(DateTime.Now.ToString() + " AMS-POC: " + Convert.ToString(ex.Message)); return(new JsonResult(new { Result = System.Net.HttpStatusCode.InternalServerError })); } return(Ok()); }
public IActionResult MicroServiceServicePointGeneration(OPLD opldObject) { try { log.Info(DateTime.Now.ToString() + " AMS-POC-MicroServiceServicePointGeneration: Read OPLD message and Start processing."); //CreateServicepoint //SakilaContext context = new SakilaContext("server=127.0.01;port=3306;database=ams;user=root;password=techM@Ups1"); SakilaContext context = new SakilaContext("server=techm.cooavdyjxzoz.us-east-1.rds.amazonaws.com;port=3306;database=ams;user=root;password=Password123"); log.Info(DateTime.Now.ToString() + " AMS-POC-MicroServiceServicePointGeneration: Getting OPLD tracking number matching DIALS record."); //Check if opld tracking number matches with dials matching number DIALS dialsObject = context.GetMatchingDialsID(opldObject.SHIP_SP_NR); ServicePoint servicePointObject = new ServicePoint(); if (!string.IsNullOrEmpty(dialsObject.TrackingNumber)) { //Match found //Compare OPLD Add1 with SP Add1 and Update timestamp and increase Stop ID ServicePoint servicePoint = context.CompareOPLDAdd1WithSPAddr1(opldObject.SHIP_ADDR_LINE_1_1); if (servicePoint != null && (servicePoint.ServicePointID != 0)) { context.UpdateServicePoint(servicePoint.ServicePointID); } else { servicePointObject = ServicePointUtility.CreateServicePoint(opldObject, dialsObject.ConsigneeName, dialsObject.ClarifiedSignature, true); log.Info(DateTime.Now.ToString() + " AMS-POC-MicroServiceServicePointGeneration: Writing ServicePoint in to DB."); //Write Servicepoint to DB context.AddNewServicePoint(servicePointObject); } } else { //Create Service Point with Stop ID = 1 servicePointObject = ServicePointUtility.CreateServicePoint(opldObject, opldObject.SHIP_ATTENTION_NAME_1, "", false); log.Info(DateTime.Now.ToString() + " AMS-POC-MicroServiceServicePointGeneration: Writing ServicePoint in to DB."); //Write Servicepoint to DB context.AddNewServicePoint(servicePointObject); } //Update OPLD Processing Status context.UpdateOPLDProcessingStatus(opldObject.SHIP_SP_NR); } catch (Exception ex) { log.Error(DateTime.Now.ToString() + " AMS-POC-MicroServiceServicePointGeneration: " + Convert.ToString(ex.ToString())); return(new JsonResult(new { Result = System.Net.HttpStatusCode.InternalServerError })); } return(Ok(new { Result = "Success" })); }
public List <actor> Listar() { List <actor> atores = null; using (var db = new SakilaContext()) { atores = db.actors .Include(x => x.films_actors) .ThenInclude(y => y.film) .ToList(); } return(atores); }
public IActionResult Index() { SakilaContext db = new SakilaContext(); var res = (from x in db.Actor select x).ToList(); foreach (var x in res) { string fn = x.FirstName; int a = 1; } return(View()); }
public List <film> Listar() { List <film> films = null; using (var db = new SakilaContext()) { films = db.films .Include(x => x.films_actors) .ThenInclude(y => y.actor) .ToList(); } return(films); }
public IActionResult MicroServiceProcessDIALSFile(DIALS dialsObject) { try { SakilaContext context = new SakilaContext("server=techm.cooavdyjxzoz.us-east-1.rds.amazonaws.com;port=3306;database=sakila;user=root;password=Password123"); context.AddNewDIALS(dialsObject); } catch (Exception ex) { log.Error(DateTime.Now.ToString() + " AMS-MicroServiceProcessOPLDNDIALSFiles: " + Convert.ToString(ex.Message)); return(new JsonResult(new { Result = System.Net.HttpStatusCode.InternalServerError })); } return(Ok(new { Result = "Success" })); }
public IActionResult MicroServiceProcessDIALSFile(DIALS dialsObject) { try { SakilaContext context = new SakilaContext("server=127.0.01;port=3306;database=ams;user=root;password=techM@Ups1"); context.AddNewDIALS(dialsObject); } catch (Exception ex) { log.Error(DateTime.Now.ToString() + " AMS-MicroServiceProcessOPLDNDIALSFiles: " + Convert.ToString(ex.Message)); return(new JsonResult(new { Result = System.Net.HttpStatusCode.InternalServerError })); } return(Ok(new { Result = "Success" })); }
public IActionResult MicroServiceProcessDIALSFile(DIALS dialsObject) { try { SakilaContext context = HttpContext.RequestServices.GetService(typeof(SakilaContext)) as SakilaContext; context.AddNewDIALS(dialsObject); } catch (Exception ex) { log.Error(DateTime.Now.ToString() + " AMS-MicroServiceProcessOPLDNDIALSFiles: " + Convert.ToString(ex.Message)); return(new JsonResult(new { Result = System.Net.HttpStatusCode.InternalServerError })); } return(Ok(new { Result = "Success" })); }
public actor GetActorFilmById(int id) { actor ator = null; using (var db = new SakilaContext()) { ator = db.actors .Include(x => x.films_actors) .ThenInclude(y => y.film) .Where(a => a.actor_id == id) .First(); } return(ator); }
//MicroService 3 public async Task <IActionResult> ProcessDIALSDataNWriteToDB() { try { string dialsFolderPath = Path.Combine(Directory.GetCurrentDirectory(), "DIALSFiles"); if (Directory.Exists(dialsFolderPath)) { var files = Directory.GetFiles(dialsFolderPath); if (files.Length > 0) { foreach (string fileName in files) { FileStream fileStream = new FileStream(Path.Combine(dialsFolderPath, fileName), FileMode.Open); using (BufferedStream bufferedStream = new BufferedStream(fileStream)) { using (StreamReader streamReader = new StreamReader(bufferedStream)) { while (!streamReader.EndOfStream) { string dialsString = await streamReader.ReadLineAsync(); //Process DIALS data var dialsObject = DIALSUtility.ProcessDIALSData(dialsString); //Store in to DB if (!string.IsNullOrEmpty(dialsObject.TrackingNumber)) { SakilaContext context = HttpContext.RequestServices.GetService(typeof(SakilaContext)) as SakilaContext; context.AddNewDIALS(dialsObject); } } } } } } } } catch { return(new JsonResult(new { Result = System.Net.HttpStatusCode.InternalServerError })); } return(Ok()); }
//MicroService 5 public IActionResult ReadMQ3ServicePointNWriteToDB() { try { //Read from MQ ServicePoint servicePointObject = CommonUtility <ServicePoint> .PullFromActiveMQ(3); //Write Servicepoint to DB SakilaContext context = HttpContext.RequestServices.GetService(typeof(SakilaContext)) as SakilaContext; context.AddNewServicePoint(servicePointObject); } catch { return(new JsonResult(new { Result = System.Net.HttpStatusCode.InternalServerError })); } return(Ok()); }
static void Main(string[] args) { SakilaContext sakila = new SakilaContext(); Film war1917 = new Film("1917", "2019 War Drama By Director Sam Mendes", "2019", 3, 5.99m, 179, 19.99m, "R"); Film joker = new Film("Joker", "Oscar-Nominated SuperHero Drama", "2019", 3, 6.99m, 182, 23.99m, "R"); Film jarjarAbrams = new Film("Star Wars: The Rise of SkyWalker", "Trash Disney Fanfic", "2019", 3, 4.99m, 202, 21.99m, "PG-13"); sakila.Film.Add(war1917); sakila.Film.Add(joker); sakila.Film.Add(jarjarAbrams); sakila.SaveChanges(); Film[] allfilms = sakila.Film.ToArray(); var newfilms = allfilms.Where(x => x.release_year == "2019"); StringBuilder html = new StringBuilder(); html.Append("<html>\n"); html.Append(" <head>"); html.Append(" <title>Sakila New Films</title>\n"); html.Append(" </head>\n"); html.Append(" <body\n"); html.Append(" <h1> New Films Coming Soon! </h1>\n"); html.Append(" <ul>\n"); foreach (var film in newfilms) { html.Append("<li>"); html.Append(film.title + " " + film.description); html.Append("</li>"); } html.Append(" </ul>\n"); html.Append(" </body>\n"); html.Append("</html>\n"); string htmlFile = "D:\\output\\newfilms.html"; File.WriteAllText(htmlFile, html.ToString()); }
//MicroService 4 public IActionResult ReadMQ2OPLDNCreateSPNPushTOMQ3() { try { //Read from MQ //OPLD opldObject = CommonUtility<OPLD>.PullFromActiveMQ(2); log.Info(DateTime.Now.ToString() + " AMS-POC: Service point genration process started."); ServicePoint servicePointObject = new ServicePoint(); var opldProcString = Request.Headers["opldProcString"]; OPLD opldObject = Newtonsoft.Json.JsonConvert.DeserializeObject <OPLD>(opldProcString); //CreateServicepoint //Check if opld tracking number matches with dials matching number SakilaContext context = HttpContext.RequestServices.GetService(typeof(SakilaContext)) as SakilaContext; DIALS dialsObject = context.GetMatchingDialsID(opldObject.TrackingNumber); if (dialsObject != null) { servicePointObject = ServicePointUtility.CreateServicePoint(opldObject, dialsObject.ConsigneeName, dialsObject.ClarifiedSignature, true); } else { servicePointObject = ServicePointUtility.CreateServicePoint(opldObject, "", "", false); } //Push OPLD in to Active MQ2 CommonUtility <ServicePoint> .PushToActiveMQ(servicePointObject, 3); log.Info(DateTime.Now.ToString() + " AMS-POC: Service point Created and Pushed to MQ3."); } catch (Exception ex) { log.Error(DateTime.Now.ToString() + " AMS-POC: " + Convert.ToString(ex.Message)); return(new JsonResult(new { Result = System.Net.HttpStatusCode.InternalServerError })); } return(Ok()); }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req, ILogger log) { try { log.LogInformation("ListStaffs function processed a request."); using (SakilaContext context = new SakilaContext()) { return(new OkObjectResult(await context.Staff.ToListAsync())); } } catch (System.Exception ex) { return(new BadRequestObjectResult( $"We apologize but something went wrong on our end.Exception:{ex.Message}")); } finally { log.LogInformation("ListStaffs function has finished processing a request."); } }
//MicroService 2 public IActionResult ProcessMQ1OPLDMessageNWriteToDBNMQ2() { try { //Read from MQ OPLD opldObject = CommonUtility <OPLD> .PullFromActiveMQ(1); //Store in to DB SakilaContext context = HttpContext.RequestServices.GetService(typeof(SakilaContext)) as SakilaContext; context.AddNewOPLD(opldObject); //Push OPLD in to Active MQ2 CommonUtility <OPLD> .PushToActiveMQ(opldObject, 2); } catch { return(new JsonResult(new { Result = System.Net.HttpStatusCode.InternalServerError })); } return(Ok()); }
public IActionResult MicroServiceServicePointGeneration(OPLD opldObject) { try { log.Info(DateTime.Now.ToString() + " AMS-POC-MicroServiceServicePointGeneration: Read OPLD message and Start processing."); //CreateServicepoint SakilaContext context = new SakilaContext("server=127.0.01;port=3306;database=ams;user=root;password=techM@Ups1");//HttpContext.RequestServices.GetService(typeof(SakilaContext)) as SakilaContext; log.Info(DateTime.Now.ToString() + " AMS-POC-MicroServiceServicePointGeneration: Getting OPLD tracking number matching DIALS record."); //Check if opld tracking number matches with dials matching number DIALS dialsObject = context.GetMatchingDialsID(opldObject.TrackingNumber); ServicePoint servicePointObject = new ServicePoint(); if (!string.IsNullOrEmpty(dialsObject.TrackingNumber)) { servicePointObject = ServicePointUtility.CreateServicePoint(opldObject, dialsObject.ConsigneeName, dialsObject.ClarifiedSignature, true); } else { servicePointObject = ServicePointUtility.CreateServicePoint(opldObject, "", "", false); } log.Info(DateTime.Now.ToString() + " AMS-POC-MicroServiceServicePointGeneration: Writing ServicePoint in to DB."); //Write Servicepoint to DB context.AddNewServicePoint(servicePointObject); //Update OPLD Processing Status context.UpdateOPLDProcessingStatus(opldObject.TrackingNumber); } catch (Exception ex) { log.Error(DateTime.Now.ToString() + " AMS-POC-MicroServiceServicePointGeneration: " + Convert.ToString(ex.Message)); return(new JsonResult(new { Result = System.Net.HttpStatusCode.InternalServerError })); } return(Ok(new { Result = "Success" })); }
public IActionResult MicroServiceProcessOPLDFile(OPLD opldObject) { try { //Push OPLD in DB SakilaContext context = HttpContext.RequestServices.GetService(typeof(SakilaContext)) as SakilaContext; context.AddNewOPLD(opldObject); log.Info(DateTime.Now.ToString() + " AMS-POC-MicroServiceProcessOPLDNDIALSFiles: OPLD Data inserted in DB."); //Push OPLD in to Active MQ2 CommonUtility <OPLD> .PushToActiveMQ(opldObject, 1); log.Info(DateTime.Now.ToString() + " AMS-MicroServiceProcessOPLDNDIALSFiles: OPLD message pushed to MQ."); } catch (Exception ex) { log.Error(DateTime.Now.ToString() + " AMS-MicroServiceProcessOPLDNDIALSFiles: " + Convert.ToString(ex.Message)); return(new JsonResult(new { Result = System.Net.HttpStatusCode.InternalServerError })); } return(Ok(new { Result = "Success" })); }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "get", Route = "GetFilm/{id}")] HttpRequest req, int id, ILogger log) { try { log.LogInformation("GetFilm function processed a request."); using (SakilaContext context = new SakilaContext()) { return(new OkObjectResult(await context.Film.Where(f => f.FilmId == id).SingleOrDefaultAsync())); } } catch (System.Exception ex) { return(new BadRequestObjectResult( $"We apologize but something went wrong on our end.Exception:{ex.Message}")); } finally { log.LogInformation("GetFilm function has finished processing a request."); } }
public IActionResult MicroServiceProcessOPLDFile(OPLD opldObject) { try { //Push OPLD in DB //SakilaContext context = HttpContext.RequestServices.GetService(typeof(SakilaContext)) as SakilaContext; SakilaContext context = new SakilaContext("server=techm.cooavdyjxzoz.us-east-1.rds.amazonaws.com;port=3306;database=ams;user=root;password=Password123"); context.AddNewOPLD(opldObject); log.Info(DateTime.Now.ToString() + " AMS-POC-MicroServiceProcessOPLDNDIALSFiles: OPLD Data inserted in DB."); //Push OPLD in to Active MQ2 CommonUtility <OPLD> .PushToActiveMQ(opldObject, 1); log.Info(DateTime.Now.ToString() + " AMS-MicroServiceProcessOPLDNDIALSFiles: OPLD message pushed to MQ."); } catch (Exception ex) { log.Error(DateTime.Now.ToString() + " AMS-MicroServiceProcessOPLDNDIALSFiles: " + Convert.ToString(ex.Message)); return(new JsonResult(new { Result = System.Net.HttpStatusCode.InternalServerError })); } return(Ok(new { Result = "Success" })); }