예제 #1
0
        public async Task <GoogleEvent.UpdateResponse> UploadData()
        {
            IsLoadingData = true;
            ObjEvent.FixDates(false);

            var request = new GoogleEventUpdateRequest {
                ObjGoogleEvent   = ObjEvent,
                RelatedOwnerGuid = App.VM.user.Guid,
            };

            try
            {
                var ws     = new WebServiceV2();
                var config = new WebServiceV2.UrlToStringConfiguration
                {
                    url        = Globals.RestApiV1 + "loft/event/" + ObjEvent.ID + "/update",
                    Type       = WebServiceV2.UrlToStringConfiguration.RequestType.JsonRaw,
                    Verb       = WebServiceV2.UrlToStringConfiguration.RequestVerb.POST,
                    RawContent = JsonConvert.SerializeObject(request),
                    timeout    = TimeSpan.FromSeconds(60)
                };
                if (string.IsNullOrWhiteSpace(ObjEvent.ID))
                {
                    config.url = Globals.RestApiV1 + "loft/event/null/update";
                }
                var res = await ws.UrlToString(config);

                if (res == null)
                {
                    Visual1993.Console.WriteLine("bad response"); return(new GoogleEvent.UpdateResponse());
                }
                var resObj = JsonConvert.DeserializeObject <GoogleEvent.UpdateResponse>(res);
                if (resObj != null)
                {
                    this.ObjEvent = resObj.item;
                    if (this.ObjEvent == null)
                    {
                        return(resObj);
                    }
                    this.ObjInternalEvent.data.RelatedGoogleEventID = this.ObjEvent.ID;
                    if (IsNew == false)
                    {
                        var resInterno = await this.ObjInternalEvent.update();
                    }
                    if (IsNew)
                    {
                        var resInterno = await this.ObjInternalEvent.insert();

                        IsNew = false;
                    }                    //qui non ci posso mettere l'else
                }
                return(resObj);
            }
            finally {
                IsLoadingData = false;
            }
        }
예제 #2
0
        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);
        }
예제 #3
0
        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));
        }