示例#1
0
        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);
            }
        }
示例#2
0
        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);
        }