public IHttpActionResult PostBanUserFromShare(FormDataCollection data) { if (!Session.Authorized) { return(Unauthorized()); } var valueMap = FormDataConverter.Convert(data); var guestId = valueMap.Get("guestId").AsInt(); var share = _shareRepo.GetUserActiveShare(Session.User.Id); if (share.Host.Id != Session.User.Id) { return(NotFound()); } var shareGuest = _shareRepo.GetGuest(share.Id, guestId); if (shareGuest == null) { return(NotFound()); } if (shareGuest.CurrentStatus == Guest.Status.Leaved) { return(NotFound()); } shareGuest.CurrentStatus = Guest.Status.Leaved; _shareRepo.LeaveShare(share.Id, shareGuest.User.Id); var msgData = new Dictionary <string, string> { { "TYPE", "SHARE_BAN" } }; #pragma warning disable 4014 FirebaseCloudMessanger.SendMessage( shareGuest.User, "Sei stato espulso", Session.User + " ti ha espulso dalla condivisione in corso", msgData, "it.gruppoinfor.hometowork.SHARE_BAN"); #pragma warning restore 4014 return(Ok(true)); }
public IHttpActionResult PostCancelShare() { if (!Session.Authorized) { return(Unauthorized()); } var share = _shareRepo.GetUserActiveShare(Session.User.Id); if (share == null) { return(NotFound()); } if (share.Host.Id != Session.User.Id) { return(NotFound()); } if (share.Status == Status.Canceled) { return(NotFound()); } _shareRepo.CancelShare(share.Id); var guests = _shareRepo.GetShareGuests(share.Id); guests.ForEach(guest => { var msgData = new Dictionary <string, string> { { "TYPE", "SHARE_CANCELED" } }; #pragma warning disable 4014 FirebaseCloudMessanger.SendMessage( guest.User, "Condivisione annullata", Session.User + " ha annullato la condivisione in corso", msgData, "it.gruppoinfor.hometowork.SHARE_CANCELED"); #pragma warning restore 4014 }); return(Ok(true)); }
public IHttpActionResult PostLeaveShare() { if (!Session.Authorized) { return(Unauthorized()); } var share = _shareRepo.GetUserActiveShare(Session.User.Id); if (share == null) { return(NotFound()); } var shareGuest = _shareRepo.GetGuest(share.Id, Session.User.Id); if (shareGuest == null) { return(NotFound()); } var leaved = _shareRepo.LeaveShare(share.Id, shareGuest.User.Id); if (!leaved) { return(Ok(false)); } var msgData = new Dictionary <string, string> { { "TYPE", "SHARE_LEAVED" } }; #pragma warning disable 4014 FirebaseCloudMessanger.SendMessage( share.Host, "Condivisione abbandonata", Session.User + " ha abbandonato la condivisione in corso", msgData, "it.gruppoinfor.hometowork.SHARE_LEAVED"); #pragma warning restore 4014 return(Ok(true)); }
public IHttpActionResult PostMessage(int chatId, FormDataCollection data) { if (!Session.Authorized) { return(Unauthorized()); } var chat = _chatRepo.GetByChatId(Session.User.Id, chatId); if (chat == null) { return(NotFound()); } var valueMap = FormDataConverter.Convert(data); var text = valueMap.Get("text"); if (text.IsNullOrWhiteSpace()) { return(BadRequest("Corpo messaggio mancante o vuoto")); } var messageId = _chatRepo.InsertMessage(Session.User.Id, chatId, text); var msgData = new Dictionary <string, string> { { "TYPE", "NEW_MESSAGE" }, { "CHAT_ID", chatId.ToString() }, { "MESSAGE_ID", messageId.ToString() } }; #pragma warning disable 4014 FirebaseCloudMessanger.SendMessage( chat.User, "Nuovo messaggio", Session.User + " ti ha inviato un nuovo messaggio", msgData, "it.gruppoinfor.hometowork.NEW_MESSAGE"); #pragma warning restore 4014 var message = _chatRepo.getMessageById(messageId); return(Ok(message)); }
public IHttpActionResult PostCompleteShare(FormDataCollection data) { if (!Session.Authorized) { return(Unauthorized()); } var currentShare = _shareRepo.GetUserActiveShare(Session.User.Id); if (currentShare == null) { return(NotFound()); } var guest = _shareRepo.GetGuest(currentShare.Id, Session.User.Id); if (guest == null) { return(NotFound()); } var valueMap = FormDataConverter.Convert(data); var lat = valueMap.Get("completeLat"); var lng = valueMap.Get("completaLng"); if (lat.IsNullOrWhiteSpace()) { return(BadRequest("Latitudine finale mancante")); } if (lng.IsNullOrWhiteSpace()) { return(BadRequest("Longitudine finale mancante")); } double completeLat; double completeLng; try { completeLat = double.Parse(lat); } catch (Exception e) { return(BadRequest("Formato latitutudine non corretto")); } try { completeLng = double.Parse(lng); } catch (Exception e) { return(BadRequest("Formato longitudine non corretto")); } var request = new DirectionsRequest() { Origin = new GoogleApi.Entities.Common.Location(guest.StartLat, guest.StartLng), Destination = new GoogleApi.Entities.Common.Location(completeLat, completeLng), Key = "AIzaSyDrnpGbytKl9jFKNTmI3B2vXh_68x3DG2Y" }; var result = GoogleMaps.Directions.Query(request); var distance = result.Routes.First().Legs.First().Distance.Value; _shareRepo.CompleteShare(currentShare.Id, Session.User.Id, completeLat, completeLng, distance); var host = currentShare.Host; var msgData = new Dictionary <string, string> { { "TYPE", "SHARE_COMPLETED" } }; #pragma warning disable 4014 FirebaseCloudMessanger.SendMessage( host, "Condivisione completata", Session.User + " ha completato la condivisione percorrendo " + distance / 1000.0 + " Km", msgData, "it.gruppoinfor.hometowork.SHARE_COMPLETED"); #pragma warning restore 4014 _userRepo.AddExpToUser(guest.User.Id, guest.Distance / 100); var completedShare = _shareRepo.GetGuest(currentShare.Id, Session.User.Id); return(Ok(completedShare)); }
public IHttpActionResult PostJoinShare(int shareId, FormDataCollection data) { if (!Session.Authorized) { return(Unauthorized()); } var valueMap = FormDataConverter.Convert(data); var lat = valueMap.Get("joinLat"); var lng = valueMap.Get("joinLng"); if (lat.IsNullOrWhiteSpace()) { return(BadRequest("Latitudine iniziale mancante")); } if (lng.IsNullOrWhiteSpace()) { return(BadRequest("Longitudine iniziale mancante")); } double joinLat; double joinLng; try { joinLat = double.Parse(lat); } catch (Exception e) { return(BadRequest("Formato latitutudine non corretto")); } try { joinLng = double.Parse(lng); } catch (Exception e) { return(BadRequest("Formato longitudine non corretto")); } var share = _shareRepo.GetUserShare(Session.User.Id, shareId); if (share == null) { return(NotFound()); } var shareGuest = _shareRepo.GetGuest(shareId, Session.User.Id); if (shareGuest != null) { if (shareGuest.CurrentStatus == Guest.Status.Leaved) { shareGuest.CurrentStatus = Guest.Status.Joined; _shareRepo.JoinShare(shareId, shareGuest.User.Id, joinLat, joinLng); } } else { _shareRepo.JoinShare(shareId, Session.User.Id, joinLat, joinLng); } var msgData = new Dictionary <string, string> { { "TYPE", "SHARE_JOIN" } }; #pragma warning disable 4014 FirebaseCloudMessanger.SendMessage( share.Host, "Nuovo ospite", Session.User + " si è unito alla condivisione in corso", msgData, "it.gruppoinfor.hometowork.SHARE_JOIN"); #pragma warning restore 4014 share = _shareRepo.GetUserShare(Session.User.Id, shareId); return(Ok(share)); }