// GET: Account/Logout public async Task<ActionResult> Logout() { /* Delete Cookie */ if (Request.Cookies["SessionId"] != null) { /* Do the logout */ using (EiaService.InterfaceClient pClient = new EiaService.InterfaceClient()) { /* Open connection */ pClient.Open(); /* Logout */ EiaService.OpObject RetObj = await pClient.LogoutAsync(Request.Cookies["SessionId"].Value); /* Cleanup */ pClient.Close(); } /* Remove session id */ Response.Cookies.Remove("SessionId"); } /* Redirect to out */ return RedirectToActionPermanent("Index", "Home"); }
/* Helper - Loads models */ private async Task<EiaService.CModel[]> GetModels() { EiaService.CModel[] aModels = null; /* Lookup in cache */ aModels = CacheProvider.GetCache().Get<EiaService.CModel[]>("EIAModels"); /* Sanity */ if (aModels == null) { /* Get from server */ using (EiaService.InterfaceClient eClient = new EiaService.InterfaceClient()) { /* Open Client */ eClient.Open(); /* Get available models */ EiaService.OpObject RetObj = await eClient.GetAvailableModelsAsync(""); /* Done with service */ eClient.Close(); /* Save models */ if (RetObj.Code == EiaService.StatusCode.Ok) { aModels = (EiaService.CModel[])RetObj.Data; CacheProvider.GetCache().Set<EiaService.CModel[]>("EIAModels", aModels, DateTime.Now.AddMonths(1)); } } } /* Done! */ return aModels; }
public async Task<JsonResult> Submit(String TemplateFile, String Params, Boolean EmailOnCompletion) { /* Sanity */ if (String.IsNullOrEmpty(Params)) return Json(new { Error = true, ErrorMsg = "Missing data in fields." }, JsonRequestBehavior.AllowGet); /* Store result of upload */ String rGuid = ""; /* Build Request */ EiaService.CModelRequest mRequest = new EiaService.CModelRequest(); Byte[] tData = Convert.FromBase64String(TemplateFile); /* Fill in data */ mRequest.TemplateWithData = tData; mRequest.Status = EiaService.RequestStatus.InQueue; mRequest.Parameters = (EiaService.RequestParameters)int.Parse(Params); mRequest.EmailOnCompletion = EmailOnCompletion; /* Connect and send the challenge */ using (EiaService.InterfaceClient pClient = new EiaService.InterfaceClient()) { /* Open connection */ pClient.Open(); /* Logout */ EiaService.OpObject RetObj = await pClient.CreateModelRequestAsync("", mRequest); /* Sanity */ if (RetObj.Code != EiaService.StatusCode.Ok) { /* Cleanup and return */ pClient.Close(); return Json(new { Error = true, ErrorMsg = RetObj.Code.ToString(), ErrorDesc = RetObj.Data.ToString() }, JsonRequestBehavior.AllowGet); } /* Set guid */ rGuid = RetObj.Data.ToString(); /* Cleanup */ pClient.Close(); } /* Done! */ return Json(new { Error = false, RequestGuid = rGuid }, JsonRequestBehavior.AllowGet); }
/* GET: /Model/GetResult */ public async Task<ActionResult> GetResult(String RequestGuid) { /* Sanity */ if (String.IsNullOrEmpty(RequestGuid)) return new HttpStatusCodeResult(404); /* Get model matching given params */ EiaService.CModelResponse Response = null; /* Connect and send the challenge */ using (EiaService.InterfaceClient pClient = new EiaService.InterfaceClient()) { /* Open connection */ pClient.Open(); /* Logout */ EiaService.OpObject RetObj = await pClient.GetModelResponseAsync("", RequestGuid, true); /* Sanity */ if (RetObj.Code != EiaService.StatusCode.Ok) { /* Cleanup and return */ pClient.Close(); /* Return error */ return new HttpStatusCodeResult(301); } /* Set status */ Response = (EiaService.CModelResponse)RetObj.Data; /* Cleanup */ pClient.Close(); } /* Sanity */ if (Response == null) return new HttpStatusCodeResult(404); /* Return file */ return File(Response.ResponseData, System.Net.Mime.MediaTypeNames.Application.Octet, Response.Model.Name + " - " + Response.Model.Country + " - " + Response.Model.Type + " - Results.xlsx"); }
public async Task<JsonResult> GetUpdate(String RequestGuid) { /* Sanity */ if (String.IsNullOrEmpty(RequestGuid)) return Json(new { Error = true, ErrorMsg = "Missing request guid." }, JsonRequestBehavior.AllowGet); /* Variables */ EiaService.RequestStatus Status = EiaService.RequestStatus.InQueue; /* Connect and send the challenge */ using (EiaService.InterfaceClient pClient = new EiaService.InterfaceClient()) { /* Open connection */ pClient.Open(); /* Logout */ EiaService.OpObject RetObj = await pClient.GetModelRequestAsync("", RequestGuid, true); /* Sanity */ if (RetObj.Code != EiaService.StatusCode.Ok) { /* Cleanup and return */ pClient.Close(); return Json(new { Error = true, ErrorMsg = RetObj.Code.ToString(), ErrorDesc = RetObj.Data.ToString() }, JsonRequestBehavior.AllowGet); } /* Set status */ Status = ((EiaService.CModelRequest)RetObj.Data).Status; /* Cleanup */ pClient.Close(); } /* Done! */ return Json(new { Error = false, RequestStatus = (int)Status }, JsonRequestBehavior.AllowGet); }
public async Task<JsonResult> SendMail(String Name, String Email, String Subject, String Body) { /* Sanity Values */ if (String.IsNullOrEmpty(Name) || String.IsNullOrEmpty(Email) || String.IsNullOrEmpty(Subject) || String.IsNullOrEmpty(Body)) return Json(new { Error = true, ErrorMsg = "Invalid Parameters or missing Information." }, JsonRequestBehavior.AllowGet); try { /* Send two mails */ EiaService.CMail pMail = new EiaService.CMail(); /* The one for us */ pMail.Body = "Email feedback from " + Name + ": " + Email + "\n\n\n" + Body; pMail.Subject = "NRG Feedback: " + Subject; pMail.MailTo = "[email protected];[email protected]"; pMail.IsHtml = false; pMail.Type = EiaService.MailType.Support; using (EiaService.InterfaceClient pClient = new EiaService.InterfaceClient()) { /* Open connection */ pClient.Open(); /* Send Mails */ EiaService.OpObject RetObj = await pClient.SendMailAsync(pMail); /* Sanity */ if (RetObj.Code != EiaService.StatusCode.Ok) if (RetObj.Data is String) throw new Exception(RetObj.Data as String); /* Cleanup */ pClient.Close(); } } catch (Exception) { return Json(new { Error = true, ErrorMsg = "The information you gave is invalid, we were unable to fulfill your request." }, JsonRequestBehavior.AllowGet); } /* Done */ return Json(new { Error = false }, JsonRequestBehavior.AllowGet); }
public async Task<JsonResult> Login(String Email, String Password) { /* Sanity */ if (String.IsNullOrEmpty(Email) || String.IsNullOrEmpty(Password)) return Json(new { Error = true, ErrorMsg = "Invalid Parameters or missing Information." }, JsonRequestBehavior.AllowGet); /* Login */ try { using (EiaService.InterfaceClient pClient = new EiaService.InterfaceClient()) { /* Open connection */ pClient.Open(); /* Send Mails */ EiaService.OpObject RetObj = await pClient.LoginAsync(Email, Password); /* Sanity */ if (RetObj.Code != EiaService.StatusCode.Ok) { if (RetObj.Data is String) throw new Exception(RetObj.Data as String); else throw new Exception(RetObj.Code.ToString()); } /* Save session id in cookies */ Response.Cookies.Add(new HttpCookie("SessionId", (String)RetObj.Data)); /* Cleanup */ pClient.Close(); } } catch (Exception) { return Json(new { Error = true, ErrorMsg = "Your combination of email/password was invalid." }, JsonRequestBehavior.AllowGet); } /* Done */ return Json(new { Error = false, Url = Url.Action("Index", "Account") }, JsonRequestBehavior.AllowGet); }
public async Task<JsonResult> SignUp(String Email, String Password, String FirstName, String LastName, String Phone) { /* Sanity */ if (String.IsNullOrEmpty(Email) || String.IsNullOrEmpty(Password)) return Json(new { Error = true, ErrorMsg = "Invalid Parameters or missing Information." }, JsonRequestBehavior.AllowGet); /* Login */ try { using (EiaService.InterfaceClient pClient = new EiaService.InterfaceClient()) { /* Open connection */ pClient.Open(); /* Send Mails */ EiaService.OpObject RetObj = await pClient.CreateUserAsync(new EiaService.CCustomer() { Email = Email, Password = Password, FirstName = FirstName, LastName = LastName, Phone = Phone, VatId = "" }); /* Sanity */ if (RetObj.Code != EiaService.StatusCode.Ok) { if (RetObj.Data is String) throw new Exception(RetObj.Data as String); else throw new Exception(RetObj.Code.ToString()); } /* Cleanup */ pClient.Close(); } } catch (Exception Ex) { return Json(new { Error = true, ErrorMsg = "Login-Error, Code: " + Ex.ToString() }, JsonRequestBehavior.AllowGet); } /* Done */ return Json(new { Error = false, Url = Url.Action("Index", "Account") }, JsonRequestBehavior.AllowGet); }