public static List <SelectListItem> DefaultSpeciesList() { //todo on the enter fish page, make buttons for the top 3 species caught over the last 20 or so entries. Then have the droplist for the rest of species? try { FishDBDataContext FishDB = new FishDBDataContext(); var id = HttpContext.Current.GetOwinContext().GetUserManager <ApplicationUserManager>().FindById(HttpContext.Current.User.Identity.GetUserId()).Id; var anglerID = FishDB.spGetAnglerID(id).ToList().First().AnglerID; var speciesList = FishDB.spGetSpeciesList(anglerID).ToList(); //var recentSpecies = FishDB.spGetLast5FishById().ToList(); List <SelectListItem> l = new List <SelectListItem>(); foreach (var i in speciesList) { l.Add(new SelectListItem { Text = i.SpeciesName, Value = i.speciesID.ToString() }); } return(l); } catch (Exception ex) { ErrorLoggingClass error = new ErrorLoggingClass(); error.logError(ex.Message, ex.Source, ex.StackTrace, "Enter Fish", "DatabaseClass", "DefaultSpeciesList", HttpContext.Current.User.Identity.Name, null); // create default list List <SelectListItem> l = new List <SelectListItem>(); l.Add(new SelectListItem { Text = "Smallmouth Bass", Value = "1" }); l.Add(new SelectListItem { Text = "Largemouth Bass", Value = "2" }); l.Add(new SelectListItem { Text = "Northern Pike", Value = "3" }); l.Add(new SelectListItem { Text = "Flathead Catfish", Value = "4" }); l.Add(new SelectListItem { Text = "Channel Catfish", Value = "5" }); l.Add(new SelectListItem { Text = "Walleye", Value = "6" }); return(l); } }
public Models.FishModels.AmazonS3Url GeneratePreSignedURL(string objectKey) { //string urlString = ""; Models.FishModels.AmazonS3Url AmazonS3Url = new Models.FishModels.AmazonS3Url(); AmazonS3Url.expires = DateTime.Now.AddDays(1); //this is needed because for some reason you cant just say: Expires = AmazonS3Url.expires below...but you can do this... weird AmazonS3Url.objectKey = objectKey; try { GetPreSignedUrlRequest request1 = new GetPreSignedUrlRequest { BucketName = _awsBucketName, Key = objectKey, Expires = DateTime.Now.AddDays(1) }; IAmazonS3 s3Client = new AmazonS3Client(_awsAccessKey, _awsSecretKey, Amazon.RegionEndpoint.USEast1); AmazonS3Url.url = s3Client.GetPreSignedURL(request1); } catch (AmazonS3Exception amazonS3Exception) { if (amazonS3Exception.ErrorCode != null && (amazonS3Exception.ErrorCode.Equals("InvalidAccessKeyId") || amazonS3Exception.ErrorCode.Equals("InvalidSecurity"))) { ErrorLoggingClass errorLog = new ErrorLoggingClass(); errorLog.logError(amazonS3Exception.Message, amazonS3Exception.Source, amazonS3Exception.StackTrace, "GeneratePreSignedURL", "DB Class", "", HttpContext.Current.User.Identity.Name, "AMAZON_S3_EXCEPTION: Check the provided AWS Credentials."); return(null); } else { ErrorLoggingClass errorLog = new ErrorLoggingClass(); errorLog.logError(amazonS3Exception.Message, amazonS3Exception.Source, amazonS3Exception.StackTrace, "GeneratePreSignedURL", "DatabaseClass", "GeneratePreSignedURL", HttpContext.Current.User.Identity.Name, null); return(null); } } catch (Exception ex) { ErrorLoggingClass errorLog = new ErrorLoggingClass(); errorLog.logError(ex.Message, ex.Source, ex.StackTrace, "GeneratePreSignedURL", "FishController", "GeneratePreSignedURL", HttpContext.Current.User.Identity.Name, ""); return(null); } return(AmazonS3Url); }
//public bool EnterFishOld(string username, Models.FishModels.Fish fish) //{ // try // { // DateTime date = new DateTime(); // date = DateTime.Now; // FishDB.EnterFish(999999, // username, fish.strSpecies, fish.strLocationName, fish.decLengthInches, fish.decWeightLbs, fish.decWaterLevel, fish.decLatitude, fish.decLongitude); // //todo fix this username =999999...not even sure wtf this is. probably from before I added userId to the user DB. Will need to get MY UserID (the int), from DB and // // save to Session for use here and other places I want userID // return true; // } // catch (Exception ex) // { // error.logError(ex.Message, ex.Source, ex.StackTrace, "Enter Fish", "DatabaseClass", "EnterFish", HttpContext.Current.User.Identity.Name, null); // return false; // } //} public bool EnterFish(Models.FishModels.Fish fish) { try { string Id = GetId(); DateTime dtEntered = new DateTime(); dtEntered = DateTime.Now; //DateTime dtCaught = //TODO: give user option to manually enter datetime caught //dateCaught FishDB.spEnterFish(Id, fish.FishID, fish.strSpecies, dtEntered, dtEntered, fish.decLengthInches, fish.decWeightLbs); //todo fix this username =999999...not even sure wtf this is. probably from before I added userId to the user DB. Will need to get MY UserID (the int), from DB and // save to Session for use here and other places I want userID //todo: fix dateCaught Parameter. Allow user to change that when entering a fish. It shouldnt always be set to DateEntered // add images foreach (FishModels.FishImage image in fish.images) { // when you write the images to DB the first time, save them to the session. // then when you get here and you have a fishID, come back and update them with fishID. // you will need ot change spEnterFish so it returns the fishID } return(true); } catch (Exception ex) { error.logError(ex.Message, ex.Source, ex.StackTrace, "Enter Fish", "DatabaseClass", "EnterFish", HttpContext.Current.User.Identity.Name, null); return(false); } }