public HttpResponseMessage GetMessagesForUser(int numberOfDays) { return(ErrorFactory.Handle(() => { var userId = User.Identity.GetUserId(); if (userId == null) { throw new Exception(); } if (numberOfDays <= 0) { throw new Exception(); } using (var unitOfWork = new UnitOfWork()) { var response = unitOfWork.Miscellaneous.GetMessagesForNumberOfDays(userId, numberOfDays); var outgoingResponse = response?.Select(x => OutgoingInboxMessage.Parse(x))?.ToList(); return JsonFactory.CreateJsonMessage(outgoingResponse, HttpStatusCode.OK, this.Request); } }, this.Request)); }
public HttpResponseMessage EditVenue(IncomingEditVenue addVenue) { return(ErrorFactory.Handle(() => { var userId = User?.Identity?.GetUserId(); if (string.IsNullOrWhiteSpace(userId)) { throw new Exception(); } using (var unitOfWork = new UnitOfWork()) { var editVenue = unitOfWork.Venues.EditVenue(userId, addVenue); unitOfWork.Complete(); try { editVenue = unitOfWork.Venues.GetVenueById(userId, editVenue.Id); } catch (Exception) { } var outgoingVenue = OutgoingVenue.Parse(editVenue); return JsonFactory.CreateJsonMessage(outgoingVenue, HttpStatusCode.OK, this.Request); } }, this.Request)); }
public HttpResponseMessage CheckStatus(int id) { return(ErrorFactory.Handle(() => { var userId = User?.Identity?.GetUserId(); if (string.IsNullOrWhiteSpace(userId)) { throw new Exception(); } using (var unitOfWork = new UnitOfWork()) { var reservation = unitOfWork.Reservations.CheckStatus(userId, id); if (reservation == null) { return JsonFactory.CreateJsonMessage(null, HttpStatusCode.OK, this.Request); } unitOfWork.Complete(); var outgoingReservation = OutgoingMinimalReservationGroup.Parse(reservation); return JsonFactory.CreateJsonMessage(outgoingReservation, HttpStatusCode.OK, this.Request); } }, this.Request)); }
public HttpResponseMessage GetUserReservations(IncomingGetUsersReservations model) { return(ErrorFactory.Handle(() => { using (var unitOfWork = new UnitOfWork()) { var userId = User?.Identity?.GetUserId(); if (string.IsNullOrWhiteSpace(userId)) { throw new Exception(); } if (model == null) { throw new InvalidModelException(); } var reservations = unitOfWork.Reservations.GetReservationsForUser(userId, model.UserId, model.StartDate, model.EndDate); var outgoingReservations = reservations?.Select(x => OutgoingMinimalReservationGroupExtra.Parse(x)); return JsonFactory.CreateJsonMessage(outgoingReservations, HttpStatusCode.OK, this.Request); } }, this.Request)); }
public HttpResponseMessage AddBlackout(Blackout blackout) { return(ErrorFactory.Handle(() => { var userId = User?.Identity?.GetUserId(); if (string.IsNullOrWhiteSpace(userId)) { throw new Exception(); } using (var unitOfWork = new UnitOfWork()) { var bl = unitOfWork.Venues.CreateBlackout(userId, blackout); unitOfWork.Complete(); var outBl = new Blackout { Id = bl.Id, StartDate = bl.StartDate, EndDate = bl.EndDate, VenueId = bl.VenueId }; var outgoingBlackout = OutgoingVenueBlackout.Parse(outBl); return JsonFactory.CreateJsonMessage(outgoingBlackout, HttpStatusCode.OK, this.Request); } }, this.Request)); }
public HttpResponseMessage SearchEmployees(IncomingHotelUserSearch userQuery) { return(ErrorFactory.Handle(() => { var userId = User?.Identity?.GetUserId(); if (userId == null) { throw new Exception("User not found."); } if (userQuery == null) { throw new InvalidModelException("hotelQuery cannot be null"); } using (var unitOfWork = new UnitOfWork()) { var hotels = unitOfWork.Hotels.SearchHotelUsers(userId, userQuery.HotelId, userQuery.Query, userQuery.StartsWith, userQuery.NumberToGet); var outgoingHotels = hotels.ToList().Select(x => OutgoingHotelUser.Parse(x)).ToList(); return JsonFactory.CreateJsonMessage(outgoingHotels, HttpStatusCode.OK, this.Request); } }, this.Request)); }
public async Task <HttpResponseMessage> Login(IncomingLogin credentials) { return(await ErrorFactory.Handle(async() => { var result = await SignInManager.PasswordSignInAsync(credentials.Email, credentials.Password, credentials.RememberMe, shouldLockout: true); switch (result) { case SignInStatus.Success: ApplicationUser user = await UserManager.FindByNameAsync(credentials.Email); return GetInformationForCurrentUserResponseMessage(user.Id); case SignInStatus.LockedOut: return JsonFactory.CreateJsonMessage(new OutgoingMessage { Message = "Your account is locked out. Please try again later.", Action = "lockedOut" }, HttpStatusCode.Forbidden, Request); case SignInStatus.RequiresVerification: return JsonFactory.CreateJsonMessage(new OutgoingMessage { Message = "Your email requires verification. Please check your email and follow the instructions.", Action = "verificationRequired" }, HttpStatusCode.Forbidden, this.Request); case SignInStatus.Failure: default: return JsonFactory.CreateJsonMessage(new OutgoingMessage { Message = "Invalid username/password combination", Action = "invalidCredentials" }, HttpStatusCode.Forbidden, this.Request); } }, this.Request)); }
public async Task <HttpResponseMessage> ForgotPassword(string email) { return(await ErrorFactory.Handle(async() => { if (string.IsNullOrWhiteSpace(email)) { throw new InvalidModelException(); } var user = await UserManager.FindByEmailAsync(email); if (user == null) { return JsonFactory.CreateJsonMessage(new OutgoingMessage { Message = "ok" }, HttpStatusCode.OK, this.Request); } var token = await UserManager.GeneratePasswordResetTokenAsync(user.Id); await this.SendForgotPasswordEmail(user, token); return JsonFactory.CreateJsonMessage(new OutgoingMessage { Message = "ok" }, HttpStatusCode.OK, this.Request); }, this.Request)); }
private HttpResponseMessage GetInformationForCurrentUserResponseMessage(string userID) { if (string.IsNullOrWhiteSpace(userID)) { try { LogoutNoRoute(); } catch (Exception) { } return(JsonFactory.CreateJsonMessage(new OutgoingMessage { Message = "An unknown error has occured.", Action = "unknownError" }, HttpStatusCode.Forbidden, this.Request)); } using (var unitOfWork = new UnitOfWork()) { var realUserInformation = unitOfWork.Users.GetUserByIdForLogin(userID, userID); if (realUserInformation == null) { return(JsonFactory.CreateJsonMessage(new OutgoingMessage { Message = "An unknown error has occured.", Action = "unknownError" }, HttpStatusCode.Forbidden, this.Request)); } var outgoingInformation = OutgoingPersonalUser.Parse(realUserInformation); return(JsonFactory.CreateJsonMessage(outgoingInformation, HttpStatusCode.OK, this.Request)); } }
public async Task <HttpResponseMessage> ChangePassword(IncomingChangePassword model) { return(await ErrorFactory.Handle(async() => { var userID = User.Identity.GetUserId(); if (userID == null) { throw new Exception(); } var pwResult = await UserManager.PasswordValidator.ValidateAsync(model.NewPassword); if (pwResult.Succeeded == false) { return JsonFactory.CreateJsonMessage(new OutgoingMessage { Message = "Invalid password", Action = "invalidPassword" }, HttpStatusCode.Forbidden, this.Request); } var result = await UserManager.ChangePasswordAsync(userID, model.CurrentPassword, model.NewPassword); if (result.Succeeded == false) { return JsonFactory.CreateJsonMessage(new OutgoingMessage { Message = "Invalid username password combo", Action = "invalidUsernamePassword" }, HttpStatusCode.Forbidden, this.Request); } return GetInformationForCurrentUserResponseMessage(userID); }, this.Request)); }
public HttpResponseMessage Hotel(IncomingBoundingBoxLocation location) { return(ErrorFactory.Handle(() => { var currentUserId = User?.Identity?.GetUserId(); if (string.IsNullOrWhiteSpace(currentUserId)) { throw new UnauthorizedAccessException(); } using (var unitOfWork = new UnitOfWork()) { var theLocation = LocationBounded.FromDegrees(location.Latitude, location.Longitude); var boundingBox = theLocation.BoundingCoordinates(location.Distance); if (boundingBox.Length != 2) { throw new Exception("The bounding box is not in the correct format."); } var bottomLeft = boundingBox[0].ConvertToLatLonLocation(); var topRight = boundingBox[1].ConvertToLatLonLocation(); var hotels = unitOfWork.Hotels.GetHotelsInRadius(currentUserId, bottomLeft, topRight, location.Distance).ToList(); var outgoingHotels = hotels.Select(x => OutgoingHotel.Parse(x)).ToList(); return JsonFactory.CreateJsonMessage(outgoingHotels, HttpStatusCode.OK, this.Request); } }, this.Request)); }
//[DebuggerStepThrough] public static async Task <HttpResponseMessage> Handle(Func <Task <HttpResponseMessage> > functionToRun, HttpRequestMessage request) { try { return(await functionToRun()); } catch (BeginTransactionException e) { return(JsonFactory.CreateJsonMessage(e.Summary, HttpStatusCode.InternalServerError, request)); } catch (AlreadyDisposedException e) { return(JsonFactory.CreateJsonMessage(new OutgoingMessage { Message = e.Message, DetailedMessage = e.DetailedMessage, Action = e.Action, DetailedAction = e.DetailedAction }, HttpStatusCode.InternalServerError, request)); } catch (UnauthorizedAccessException) { return(JsonFactory.CreateJsonMessage(new OutgoingMessage { Message = "You are not authorized to view this content.", Action = "unauthorized" }, HttpStatusCode.Forbidden, request)); } catch (BaseException e) { return(JsonFactory.CreateJsonMessage(new OutgoingMessage { Message = e.Message, DetailedMessage = e.DetailedMessage, Action = e.Action, DetailedAction = e.DetailedAction }, HttpStatusCode.InternalServerError, request)); } catch (Exception e) { return(JsonFactory.CreateJsonMessage(new OutgoingMessage { Message = e.Message }, HttpStatusCode.InternalServerError, request)); } }
public HttpResponseMessage Logout() { return(ErrorFactory.Handle(() => { LogoutNoRoute(); return JsonFactory.CreateJsonMessage(new OutgoingMessage { Message = "Logged out successfully!" }, HttpStatusCode.OK, this.Request); }, this.Request)); }
public async Task <HttpResponseMessage> AddIcon(IncomingBase64File model) { return(await ErrorFactory.Handle(async() => { var userID = User.Identity.GetUserId(); if (userID == null) { throw new Exception(); } using (var unitOfWork = new UnitOfWork()) { try { if (model != null && !string.IsNullOrWhiteSpace(model.Data)) { //This is added to help yogita with her base64 problems. model.Data = model.Data.Replace(' ', '+'); var data = ImageFactory.ConvertBase64ToArray(model.Data); GalleryManager galMan = new GalleryManager(); var pictureId = await galMan.UploadImage(data, userID, ImageFormat.Png); if (pictureId == null) { throw new Exception(); } var icon = unitOfWork.Pictures.CreateIconLink(userID, pictureId ?? Guid.NewGuid()); unitOfWork.Complete(); return JsonFactory.CreateJsonMessage(OutgoingIcon.Parse(icon), HttpStatusCode.OK, this.Request); } } catch (Exception) { //Maybe try to delete image. } return JsonFactory.CreateJsonMessage(new OutgoingMessage { Action = "unknownError" }, HttpStatusCode.InternalServerError, this.Request); } }, this.Request)); }
public HttpResponseMessage GetLatestTermsAndConditions() { return(ErrorFactory.Handle(() => { using (var unitOfWork = new UnitOfWork()) { var response = unitOfWork.Miscellaneous.GetLatestTermsAndConditions(); var outgoingResponse = OutgoingMiscellaneousHtml.Parse(response); return JsonFactory.CreateJsonMessage(outgoingResponse, HttpStatusCode.OK, this.Request); } }, this.Request)); }
public HttpResponseMessage GetSpecialMessageByVenueId(int venueId) { return(ErrorFactory.Handle(() => { using (var unitOfWork = new UnitOfWork()) { var existingMessage = unitOfWork.Miscellaneous.GetMessageByVenueId(venueId); var outgoingMiscellaneousHtml = OutgoingMiscellaneousHtml.Parse(existingMessage); return JsonFactory.CreateJsonMessage(outgoingMiscellaneousHtml, HttpStatusCode.OK, this.Request); } }, this.Request)); }
public HttpResponseMessage AddNewMessage(CreateMessage addMessage) { return(ErrorFactory.Handle(() => { using (var unitOfWork = new UnitOfWork()) { var newMessage = unitOfWork.Miscellaneous.AddMessage(addMessage); unitOfWork.Complete(); var outgoingResponse = OutgoingMiscellaneousHtml.Parse(newMessage); return JsonFactory.CreateJsonMessage(outgoingResponse, HttpStatusCode.OK, this.Request); } }, this.Request)); }
public HttpResponseMessage UpdateSpecialMessage(IncomingSpecialMessage updateSpecialMessage) { return(ErrorFactory.Handle(() => { using (var unitOfWork = new UnitOfWork()) { var updatedSpecialMessage = unitOfWork.Miscellaneous.UpdateSpecialMessage(updateSpecialMessage); unitOfWork.Complete(); var outgoingMiscellaneousHtml = OutgoingMiscellaneousHtml.Parse(updatedSpecialMessage); return JsonFactory.CreateJsonMessage(outgoingMiscellaneousHtml, HttpStatusCode.OK, this.Request); } }, this.Request)); }
public HttpResponseMessage GetIcon(int iconId) { return(ErrorFactory.Handle(() => { var userID = User.Identity.GetUserId(); if (userID == null) { throw new Exception(); } using (var unitOfWork = new UnitOfWork()) { var icon = unitOfWork.Pictures.GetIconLink(userID, iconId); return JsonFactory.CreateJsonMessage(OutgoingIcon.Parse(icon), HttpStatusCode.OK, this.Request); } }, this.Request)); }
public HttpResponseMessage SearchMinimalUsers(string query) { return(ErrorFactory.Handle(() => { var userId = User?.Identity?.GetUserId(); if (userId == null) { throw new Exception("User not found."); } using (var unitOfWork = new UnitOfWork()) { var users = unitOfWork.Users.SearchUserByIdOrEmailMINIMAL(userId, query); var outgoingUsers = users.ToList().Select(x => OutgoingIdEmailUser.Parse(x)).ToList(); return JsonFactory.CreateJsonMessage(outgoingUsers, HttpStatusCode.OK, this.Request); } }, this.Request)); }
public HttpResponseMessage HotelsByUserId(string userId) { return(ErrorFactory.Handle(() => { var currentUserId = User?.Identity?.GetUserId(); if (string.IsNullOrWhiteSpace(currentUserId)) { throw new Exception(); } using (var unitOfWork = new UnitOfWork()) { var hotels = unitOfWork.Hotels.GetHotelsByUserId(userId).ToList(); var outgoingHotels = hotels.Select(x => OutgoingHotel.Parse(x)).ToList(); return JsonFactory.CreateJsonMessage(outgoingHotels, HttpStatusCode.OK, this.Request); } }, this.Request)); }
public HttpResponseMessage SearchHotels(IncomingSearchHotels hotelQuery) { return(ErrorFactory.Handle(() => { var userId = User?.Identity?.GetUserId(); if (userId == null) { throw new Exception("User not found."); } using (var unitOfWork = new UnitOfWork()) { var hotels = unitOfWork.Hotels.SearchHotels(userId, hotelQuery.query, hotelQuery.startingIndex, hotelQuery.numberToGet, hotelQuery.IncludeHidden); var outgoingHotels = hotels.ToList().Select(x => OutgoingDetailedHotel.Parse(x)).ToList(); return JsonFactory.CreateJsonMessage(outgoingHotels, HttpStatusCode.OK, this.Request); } }, this.Request)); }
public HttpResponseMessage GetHotelPermissionsObjectForUser(int hotelId) { return(ErrorFactory.Handle(() => { var userId = User?.Identity?.GetUserId(); if (userId == null) { throw new Exception("User not found."); } using (var unitOfWork = new UnitOfWork()) { var perms = unitOfWork.Hotels.GetPermissionsForUserAtHotel(userId, hotelId); var outgoingperms = OutgoingHotelPermissions.Parse(perms); return JsonFactory.CreateJsonMessage(outgoingperms, HttpStatusCode.OK, this.Request); } }, this.Request)); }
public HttpResponseMessage BeginReservationProcess(IncomingBeginReservation reservation) { return(ErrorFactory.Handle(() => { var userId = User?.Identity?.GetUserId(); if (string.IsNullOrWhiteSpace(userId)) { throw new Exception(); } var dbModel = reservation.CreateDBModel(); using (var unitOfWork = new UnitOfWork()) { var summary = unitOfWork.Reservations.BeginReservation(userId, dbModel); return JsonFactory.CreateJsonMessage(summary, HttpStatusCode.OK, this.Request); } }, this.Request)); }
public HttpResponseMessage GetIcons() { return(ErrorFactory.Handle(() => { var userID = User.Identity.GetUserId(); if (userID == null) { throw new Exception(); } using (var unitOfWork = new UnitOfWork()) { var icons = unitOfWork.Pictures.GetAllIcons(userID); var outgoingIcons = icons?.Select(x => OutgoingIcon.Parse(x))?.ToList(); return JsonFactory.CreateJsonMessage(outgoingIcons, HttpStatusCode.OK, this.Request); } }, this.Request)); }
public HttpResponseMessage VenueByHotel(int hotelId, bool includeHidden = false) { return(ErrorFactory.Handle(() => { var userId = User?.Identity?.GetUserId(); if (string.IsNullOrWhiteSpace(userId)) { throw new Exception(); } using (var unitOfWork = new UnitOfWork()) { var venues = unitOfWork.Venues.GetVenuesByHotelId(userId, hotelId, includeHidden).ToList(); var outgoingVenues = venues.Select(x => OutgoingMinimalVenue.Parse(x)).ToList(); return JsonFactory.CreateJsonMessage(outgoingVenues, HttpStatusCode.OK, this.Request); } }, this.Request)); }
public HttpResponseMessage Venue(int id) { return(ErrorFactory.Handle(() => { var userId = User?.Identity?.GetUserId(); if (string.IsNullOrWhiteSpace(userId)) { throw new Exception(); } using (var unitOfWork = new UnitOfWork()) { var venue = unitOfWork.Venues.GetVenueById(userId, id); var outgoingVenues = OutgoingVenue.Parse(venue); return JsonFactory.CreateJsonMessage(outgoingVenues, HttpStatusCode.OK, this.Request); } }, this.Request)); }
public HttpResponseMessage GetReservation(int resId) { return(ErrorFactory.Handle(() => { using (var unitOfWork = new UnitOfWork()) { var userId = User?.Identity?.GetUserId(); if (string.IsNullOrWhiteSpace(userId)) { throw new Exception(); } var reservation = unitOfWork.Reservations.GetReservationWithItems(userId, resId); var outgoingReservations = OutgoingReservationGroup.Parse(reservation); return JsonFactory.CreateJsonMessage(outgoingReservations, HttpStatusCode.OK, this.Request); } }, this.Request)); }
public HttpResponseMessage GetBlackoutsForVenue(IncomingBlackoutVenueCheck venueBlackout) { return(ErrorFactory.Handle(() => { var userId = User?.Identity?.GetUserId(); if (string.IsNullOrWhiteSpace(userId)) { throw new Exception(); } using (var unitOfWork = new UnitOfWork()) { var blackouts = unitOfWork.Venues.GetBlackoutsForVenue(userId, venueBlackout.VenueId, venueBlackout.StartDate, venueBlackout.EndDate); var outgoingBlackouts = blackouts.Select(x => OutgoingVenueBlackout.Parse(x)).ToList(); return JsonFactory.CreateJsonMessage(outgoingBlackouts, HttpStatusCode.OK, this.Request); } }, this.Request)); }
public HttpResponseMessage SearchAllReservations(IncomingSearchAllReservation model) { return(ErrorFactory.Handle(() => { using (var unitOfWork = new UnitOfWork()) { var userId = User?.Identity?.GetUserId(); if (string.IsNullOrWhiteSpace(userId)) { throw new Exception(); } var reservations = unitOfWork.Reservations.SearchAllReservations(userId, model.Query, model.SearchType, model.StartDate, model.EndDate).ToList(); var outgoingReservations = reservations.Select(x => OutgoingMinimalReservationGroupExtra.Parse(x)).ToList(); return JsonFactory.CreateJsonMessage(outgoingReservations, HttpStatusCode.OK, this.Request); } }, this.Request)); }