Exemplo n.º 1
0
        public dynamic FormToOjbect(  )
        {
            var     tablename = FormCollection["_tablename"];
            var     cols      = DB.UniClient.DbMaintenance.GetColumnInfosByTableName(tablename);
            dynamic result    = new System.Dynamic.ExpandoObject();

            foreach (var cinfo in cols)
            {
                if (FormCollection.ContainsKey(cinfo.DbColumnName))
                {
                    (result as ICollection <KeyValuePair <string, object> >).Add(new KeyValuePair <string, object>(cinfo.DbColumnName,
                                                                                                                   FormCollection[cinfo.DbColumnName]));
                }
            }
            return(result);
        }
Exemplo n.º 2
0
        public Dictionary <string, object> FormToDic(string tablename, bool isprefixtableName = false)
        {
            if (isprefixtableName)
            {
                tablename = APPCommon.GetWTableName(tablename);
            }
            var cols = DB.UniClient.DbMaintenance.GetColumnInfosByTableName(tablename);
            Dictionary <string, object> dic = new Dictionary <string, object>();

            foreach (var cinfo in cols)
            {
                if (cinfo.DbColumnName.ToLower() != "id" && FormCollection.ContainsKey(cinfo.DbColumnName))
                {
                    dic.Add(cinfo.DbColumnName, FormCollection[cinfo.DbColumnName]);
                }
            }
            return(dic);
        }
Exemplo n.º 3
0
        public static T As <T>(this FormCollection responseData) where T : class
        {
            var instance = Activator.CreateInstance <T>();

            var properties = typeof(T).GetProperties().Where(x => Attribute.IsDefined(x, typeof(JsonPropertyAttribute)));

            foreach (var propertyInfo in properties)
            {
                var jsonPropertyAttributes = propertyInfo.GetCustomAttributes(typeof(JsonPropertyAttribute), false);

                var jsonPropertyName = ((JsonPropertyAttribute)jsonPropertyAttributes.FirstOrDefault())?.PropertyName;

                var value = responseData.ContainsKey(jsonPropertyName) ? responseData[jsonPropertyName].ToString() : string.Empty;

                propertyInfo.SetValue(instance, value);
            }

            return(instance);
        }
        public async Task <IActionResult> Results(FormCollection formCollection)
        {
            string query = "";

            if (formCollection.ContainsKey("query"))
            {
                query = formCollection["query"];
            }

            if (query.Trim().Length < 3)
            {
                return(Redirect("/"));
            }

            SearchResultModelView retval = new SearchResultModelView();

            retval.Query       = query;
            retval.ShipClasses = await SiteStatics.Context.ShipClasses
                                 .Where(x => x.Name.Contains(query, StringComparison.CurrentCultureIgnoreCase))
                                 .ToListAsync();

            retval.Vessels = await SiteStatics.Context.Vessels
                             .Include(x => x.ShipClass)
                             .Where(x => x.Name.Contains(query, StringComparison.CurrentCultureIgnoreCase))
                             .ToListAsync();

            retval.Events = await SiteStatics.Context.Event
                            .Where(x => x.Description.Contains(query, StringComparison.CurrentCultureIgnoreCase) || x.Title.Contains(query, StringComparison.CurrentCultureIgnoreCase))
                            .ToListAsync();

            retval.Locations = await SiteStatics.Context.Locations
                               .Where(x => x.Name.Contains(query, StringComparison.CurrentCultureIgnoreCase))
                               .ToListAsync();



            return(View(retval));
        }
        public static HttpResponseMessage Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("CreateItem function invoked");

            //
            // Declare variables
            // ------------------------------------
            //

            FormCollection reqCollection     = (FormCollection)req.Form;
            Dictionary <string, string> dict = new Dictionary <string, string>();
            var response = new HttpResponseMessage();

            //
            // Check for request validity, if not exit immediately
            // --------------------------------------------------------
            //


            // if there's more than one image, then there's a problem
            if (reqCollection.Files.Count != 1)
            {
                response.StatusCode   = HttpStatusCode.BadRequest;
                response.ReasonPhrase = "Bad Request: Request should contain one and only one image.";

                return(response);
            }

            // if that one file is not an image file, there's a problem
            var contenttype = reqCollection.Files[0].ContentType;

            if (!contenttype.StartsWith("image"))
            {
                response.StatusCode   = HttpStatusCode.BadRequest;
                response.ReasonPhrase = "Bad Request: Attached file is not an image.";

                return(response);
            }

            // if request doesn't contain the correct keys then there's a problem
            if (!reqCollection.ContainsKey("country") || !reqCollection.ContainsKey("city"))
            {
                response.StatusCode   = HttpStatusCode.BadRequest;
                response.ReasonPhrase = "Bad Request: Request doesn't contain the correct keys.";

                return(response);
            }

            foreach (var key in reqCollection.Keys)
            {
                string value = reqCollection[key.ToString()];

                if (String.IsNullOrEmpty(value))
                {
                    response.StatusCode   = HttpStatusCode.BadRequest;
                    response.ReasonPhrase = "Bad Request: Request contains null value(s).";

                    return(response);
                }
                else
                {
                    dict.Add(key, value);
                }
            }

            // string city, country;
            // dict.TryGetValue("city", out city);
            // dict.TryGetValue("country", out country);
            // log.LogInformation($"[CreateItem] Request: {city}, {country}" );

            //
            // Do the image resize
            // -------------------
            //

            var filename  = reqCollection.Files[0].FileName;
            var extension = Path.GetExtension(filename);
            var encoder   = GetEncoder(extension);

            if (encoder != null)
            {
                var    thumbnailWidth = Convert.ToInt32(Environment.GetEnvironmentVariable("THUMBNAIL_WIDTH"));
                Stream inputimage     = reqCollection.Files[0].OpenReadStream();

                using (var output = new MemoryStream())
                    using (Image <Rgba32> img = (Image <Rgba32>)Image.Load(inputimage))
                    {
                        var divisor = img.Width / thumbnailWidth;
                        var height  = Convert.ToInt32(Math.Round((decimal)(img.Height / divisor)));
                        img.Mutate(x => x.Resize(thumbnailWidth, height));
                        img.Save(output, encoder);
                        output.Position = 0;

                        byte[] outputba = output.ToArray();
                        response.Content = new ByteArrayContent(outputba);
                        response.Content.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg");

                        return(response);
                    }
            }
            else
            {
                response.StatusCode   = HttpStatusCode.BadRequest;
                response.ReasonPhrase = "Bad Request: Image type not supported.";

                return(response);
            }

            //
            // Create a new entry in Collections table
            // -----------------------------------------------
            // - Generate GUID for the image as rowKey


            //
            // Save the full-size image to blob container pinimage
            // ----------------------------------------------
            // - Use the GUID as the filename



            //
            // Save the thumbnail to blob container pinthumb
            // ----------------------------------------------
            // - Use the GUID+"-thumb" as the filename
        }