Example #1
0
        public int Post(MediaProfileRequest model)
        {
            int OutputId = 0;

            DataProvider.ExecuteNonQuery(GetConnection, "dbo.Media_Insert"
                                         , inputParamMapper : delegate(SqlParameterCollection paramCollection)
            {
                paramCollection.AddWithValue("@MediaType", model.MediaType);
                paramCollection.AddWithValue("@ContentType", model.ContentType);
                paramCollection.AddWithValue("@UserId", model.UserId);
                paramCollection.AddWithValue("@FilePath", model.FilePath);


                SqlParameter p = new SqlParameter("@MediaId", System.Data.SqlDbType.Int);

                p.Direction = System.Data.ParameterDirection.Output;

                paramCollection.Add(p);
            }, returnParameters : delegate(SqlParameterCollection param)
            {
                int.TryParse(param["@MediaId"].Value.ToString(), out OutputId);
            }
                                         );


            return(OutputId);
        }
Example #2
0
        public HttpResponseMessage Post(string MediaType)
        {
            HttpResponseMessage result = null;
            var httpRequest            = HttpContext.Current.Request;

            if (httpRequest.Files.Count > 0)
            {
                var    docfiles   = new List <string>();
                bool   amazonCall = false;
                string keyName    = "";
                foreach (string file in httpRequest.Files)
                {
                    var postedFile    = httpRequest.Files[file];
                    var localFilePath = HttpContext.Current.Server.MapPath("~/" + postedFile.FileName);
                    var extentionType = Path.GetExtension(postedFile.FileName);
                    int themeId       = 196;
                    keyName = Guid.NewGuid().ToString() + extentionType;//.Substring(0, 12);
                    postedFile.SaveAs(localFilePath);
                    amazonCall = MediaFileService.sendMyFileToS3(localFilePath, keyName);

                    //creating thumbnail of image and sending to database
                    var thumbPath = HttpContext.Current.Server.MapPath("~/thumbnail" + postedFile.FileName);
                    ThumbnailService.ResizeImage(localFilePath, thumbPath, 400, 400, ImageFormat.Jpeg);
                    amazonCall = MediaFileService.sendMyFileToS3(thumbPath, "thumbnail/" + keyName);

                    MediaProfileRequest request = new MediaProfileRequest();
                    request.MediaType    = MediaType;
                    request.ContentType  = MimeMapping.GetMimeMapping(postedFile.FileName);
                    request.UserId       = UserService.GetCurrentUserId();
                    request.FilePath     = ConfigService.uploadFileS3Prefix + "/" + keyName;
                    request.MediaThemeId = themeId++;
                    int MediaId = this._mediaService.Post(request);
                    ItemResponse <int> response = new ItemResponse <int>();
                    response.Item = MediaId;

                    docfiles.Add(localFilePath);
                    result = Request.CreateResponse(HttpStatusCode.OK, response);
                    return(result);
                }
                result = Request.CreateResponse(HttpStatusCode.Created, keyName);
            }
            else
            {
                result = Request.CreateResponse(HttpStatusCode.BadRequest);
            }
            return(result);
        }