Ejemplo n.º 1
0
        //rds related
        private bool UpdateRDS(IPrincipal user, MultipartFileData file, MultipartFormDataStreamProvider provider)
        {
            string filename       = file.Headers.ContentDisposition.FileName.Replace("\"", "");
            string objectFinal    = keyName + "/" + user.Identity.GetUserName() + "/" + filename;
            string uploadtime     = DateTime.Now.ToString();
            string userid         = user.Identity.GetUserId();
            string objectDesc     = provider.FormData.GetValues("filedescription")[0];
            string objectSongname = provider.FormData.GetValues("filesong")[0];
            string objectLanguage = provider.FormData.GetValues("filelanguage")[0];
            string objectGenre    = provider.FormData.GetValues("filegenre")[0];
            int    iPublic        = provider.FormData.GetValues("filepublic")[0] == "true" ? 1 : 0;

            //check if entry already exists based on objectFinal (update or insert)
            bool bInsert = true;
            int  objid   = 0;

            using (TuneWorldDBEntities entities = new TuneWorldDBEntities())
            {
                var entity = entities.Objects.Where(e => e.UserId.Equals(userid) && e.ObjectUploadLink.Equals(objectFinal));
                if (entity.Count() > 0)
                {
                    bInsert = false;
                    objid   = entity.First().ObjectId;
                }
            }

            string urlString = "";

            if (iPublic == 1)
            {
                //here it might not work for other region objects edit later because of region endpoint
                //https://s3.amazonaws.com/tuneworldmain/TuneWorldFolder/bcd%40xyz/Happy+Birthday+Tune.txt
                //urlString = "https://s3.amazonaws.com/" + bucketName + "/" + HttpUtility.UrlEncode(objectFinal);
                string cloudfrontobjectFinal = user.Identity.GetUserName() + "/" + filename;
                urlString = cloudfrontlink + HttpUtility.UrlEncode(cloudfrontobjectFinal);
            }
            else
            {
                using (client = new AmazonS3Client(awskey, awssecret, new AmazonS3Config
                {
                    RegionEndpoint = regionep,
                    UseAccelerateEndpoint = true
                }))
                {
                    urlString = GeneratePreSignedDownloadURL(objectFinal);
                }
            }


            ObjectModel obj    = new ObjectModel(userid, filename, objectDesc, objectFinal, urlString, uploadtime, iPublic, objectSongname, objectLanguage, objectGenre);
            string      cmdstr = "";

            if (bInsert)
            {
                cmdstr = obj.ObjectInsertDB("Objects");
            }
            else
            {
                cmdstr = obj.ObjjectUpdateDB("Objects", objid);
            }
            DBAccess.DBAccess.InsertUpdateDeleteIntoDB(cmdstr);
            return(true);
        }