public async Task <CommonClasses.GoogleEvent.EventsResponse> DownloadEvents() { try { var ws = new Visual1993.Data.WebServiceV2(); var res = await ws.UrlToString(Globals.RestApiV1 + "loft/events"); return(JsonConvert.DeserializeObject <GoogleEvent.EventsResponse>(res)); } catch { return(new GoogleEvent.EventsResponse()); } }
public async Task <CommonClasses.GoogleEvent.EventsResponse> DownloadEvents() { try { var ws = new Visual1993.Data.WebServiceV2(); var res = await ws.UrlToString(Globals.RestApiV1 + "loft/events"); var events = JsonConvert.DeserializeObject <GoogleEvent.EventsResponse>(res); foreach (var objEvent in events.items) { objEvent.FixDates(IsInput: true); } return(events); } catch { return(new GoogleEvent.EventsResponse()); } }
public async Task <WebServiceV2.DefaultResponse> SendMail(string oggetto, string msgStr, string from, string to, bool isHtml = false) { var output = new WebServiceV2.DefaultResponse(); try { var mail = new MailRESTRequest { From = from, To = to, IsBodyHtml = isHtml, SmtpProvider = MailRESTRequest.SmtpProviderEnum.Luiss, Body = msgStr, Subject = oggetto }; var web = new Visual1993.Data.WebServiceV2(); var config = new WebServiceV2.UrlToStringConfiguration { url = MainClass.Visual1993RestServer + "visual1993/mail/send", Type = WebServiceV2.UrlToStringConfiguration.RequestType.JsonRaw, Verb = WebServiceV2.UrlToStringConfiguration.RequestVerb.POST, RawContent = JsonConvert.SerializeObject(mail) }; var res = await web.UrlToString(config); var resAsObj = JsonConvert.DeserializeObject <WebServiceV2.DefaultResponse>(res); if (resAsObj.state != WebServiceV2.WebRequestState.Ok) { output.errorMessage = "mail not sent. Error: " + resAsObj.errorMessage; } //ma non impostare lo stato a !=Ok perchè la richiesta in se è andata a buon fine } catch (Exception ex) { output.errorMessage = ex.Message; } return(output); }
public async Task <string> UpdateEvent(GoogleEvent i, Guid OwnerGuid) { Event eventoEsistente = null; //verifica se fare update o insert var IsUpdate = (string.IsNullOrWhiteSpace(i.ID) == false); if (i.ID == "null") { IsUpdate = false; } if (IsUpdate == false) { EventsResource.GetRequest request = Generic.Calendar.Events.Get(MainClass.StudentsCalendar, i.ID); try { eventoEsistente = await request.ExecuteAsync(); } catch { } IsUpdate = eventoEsistente != null; } GoogleEvent.UpdateResponse output = new GoogleEvent.UpdateResponse(); try { eventoEsistente = EventMixedFromGoogle(i, eventoEsistente); if (IsUpdate) { EventsResource.UpdateRequest request = Generic.Calendar.Events.Update( eventoEsistente, MainClass.StudentsCalendar, eventoEsistente.Id ); eventoEsistente = await request.ExecuteAsync(); } else { eventoEsistente.Id = null; EventsResource.InsertRequest request = Generic.Calendar.Events.Insert( eventoEsistente, MainClass.StudentsCalendar ); eventoEsistente = await request.ExecuteAsync(); } if (eventoEsistente != null) { output.item = eventoEsistente.ToGoogleEvent(); output.state = Visual1993.Data.WebServiceV2.WebRequestState.Ok; } } catch (Exception ex) { output.state = Visual1993.Data.WebServiceV2.WebRequestState.GenericError; output.errorMessage = ex.Message; } //manda la mail al Loft team //prendi le info dell'utente per la mail //var internalEvent = (await InternalEvent.getAllFromGoogleID(i.ID)).items.FirstOrDefault(); //if (internalEvent == null) { output.errorMessage = "Impossibile trovare l'evento correlato"; return JsonConvert.SerializeObject(output);} var utente = (await User.GetOne(OwnerGuid)).items.FirstOrDefault(); if (utente == null) { output.errorMessage = "Impossibile trovare l'utente che ha inserito l'evento"; return(JsonConvert.SerializeObject(output)); } try { var msgStr = "<html><body>" + "<p>Nome: " + i.Name + "</p>" + "<p>Inizio: " + i.StartDate.ToString() + "</p>" + "<p>Fine: " + i.EndDate.ToString() + "</p>" + "<p>Owner: " + i.OwnerName + "</p>" + "<p>Luogo: " + i.Luogo + "</p>" + "<p>Descrizione: " + i.Description + "</p>" + "<p><a href=\"" + MainClass.ExternalAccessBaseUri + MainClass.LoftPrefix + "event/" + i.InternalEventGuid + "/accept\">Accetta</a></p>" + "<p><a href=\"" + MainClass.ExternalAccessBaseUri + MainClass.LoftPrefix + "event/" + i.InternalEventGuid + "/deny\">Rifiuta</a></p>" + "</body></html>" ; var mail = new MailRESTRequest { From = utente?.data?.Email ?? null, To = MainClass.StaffMail, Cc = MainClass.StaffCcMail, IsBodyHtml = true, SmtpProvider = MailRESTRequest.SmtpProviderEnum.Luiss, Body = msgStr, Subject = "Prenotazione evento Loft" }; var web = new Visual1993.Data.WebServiceV2(); var config = new WebServiceV2.UrlToStringConfiguration { url = MainClass.Visual1993RestServer + "visual1993/mail/send", Type = WebServiceV2.UrlToStringConfiguration.RequestType.JsonRaw, Verb = WebServiceV2.UrlToStringConfiguration.RequestVerb.POST, RawContent = JsonConvert.SerializeObject(mail) }; var res = await web.UrlToString(config); var resAsObj = JsonConvert.DeserializeObject <WebServiceV2.DefaultResponse>(res); if (resAsObj.state != WebServiceV2.WebRequestState.Ok) { output.errorMessage = "mail not sent. Error: " + resAsObj.errorMessage; } //ma non impostare lo stato a !=Ok perchè la richiesta in se è andata a buon fine } catch (Exception ex) { output.errorMessage = ex.Message; } return(JsonConvert.SerializeObject(output)); }