コード例 #1
0
ファイル: FileLibrary.cs プロジェクト: omeryesil/awapicms
        /// <summary>
        /// Uploads and saves a file
        /// </summary>
        /// <param name="siteId"></param>
        /// <param name="groupIds"></param>
        /// <param name="userId"></param>
        /// <param name="title"></param>
        /// <param name="description"></param>
        /// <param name="fileFullPath"></param>
        /// <param name="fileContent"></param>
        /// <param name="isEnabled"></param>
        /// <param name="size">if the file is an image and the size is set then the image will be resized</param>
        /// <returns></returns>
        public long Upload(long siteId, long[] groupIds, long userId, string title, string description,
                           string fileFullPath, System.IO.Stream fileStream, bool isEnabled, string size)
        {
            //throw error in case of validation problem
            ValidateToUpdateFile(siteId, userId, groupIds);

            //SAVE THE FILE ------------------------------------------------------
            awFile file = new awFile();

            file.fileId = MiscLibrary.CreateUniqueId();

            string     resourceFileName = GetFileNameOnly(fileFullPath);
            string     extension        = GetFileExension(resourceFileName);
            bool       isVideoFile      = _videoLib.isVideoFile(extension);
            int        contentLength    = (int)fileStream.Length;
            string     filePath         = "";
            bool       saveOnLocal      = isVideoFile || !FileAmazonS3.SaveOnAmazonS3();
            SAVED_FILE savedFileInfo    = new SAVED_FILE();

            //SAVE THE FILE FIRST
            try
            {
                file.contentType = GetContentType(AWAPI_BusinessLibrary.library.ConfigurationLibrary.Config.fileMimeXMLPath, extension);

                filePath      = CreateFilePath(saveOnLocal, siteId, file.fileId, extension);
                savedFileInfo = SaveFile(siteId, saveOnLocal, file.contentType, filePath, fileStream, size.Trim());

                file.isOnLocal     = saveOnLocal;
                file.contentSize   = contentLength;
                file.path          = savedFileInfo.filePath.ToLower();
                file.siteId        = siteId;
                file.title         = String.IsNullOrEmpty(title) ? resourceFileName : title;
                file.description   = description;
                file.link          = GetUrl(file.fileId, savedFileInfo.filePath, "").ToLower();
                file.pubDate       = DateTime.Now;
                file.lastBuildDate = DateTime.Now;
                file.isEnabled     = isEnabled;
                file.userId        = userId;
                file.createDate    = DateTime.Now;

                _context.awFiles.InsertOnSubmit(file);
                _context.SubmitChanges();
            }
            catch (Exception ex)
            {
                DeleteFromStorage(siteId, saveOnLocal, filePath);
                throw ex;
            }

            //add file to groups
            AddFileToGroups(file.fileId, groupIds);

            //IF FILE IS A VIDEO FILE THEN CONVERT IT
            if (isVideoFile)
            {
                IfVideoConvertToFLV(file.fileId);
            }

            return(file.fileId);
        }
コード例 #2
0
ファイル: PollLibrary.cs プロジェクト: omeryesil/awapicms
        /// <summary>
        ///
        /// </summary>
        /// <param name="pollId"></param>
        /// <param name="pollChoiceId"></param>
        public void AnswerPoll(long pollId, long pollChoiceId)
        {
            awPollChoice choice = (from l in _context.awPollChoices
                                   where l.pollId.Equals(pollId) && l.pollChoiceId.Equals(pollChoiceId) &&
                                   l.awPoll.isEnabled && l.awPoll.awSite_Poll.isEnabled
                                   select l).FirstOrDefault <awPollChoice>();

            if (choice == null)
            {
                throw new Exception(ErrorLibrary.ErrorMessage(ErrorLibrary.POLL.DOES_NOT_EXIST));
            }

            int dateBetween = MiscLibrary.IsDateBetween(DateTime.Now,
                                                        choice.awPoll.pubDate,
                                                        choice.awPoll.pubEndDate);

            switch (dateBetween)
            {
            case -1:
                throw new Exception(ErrorLibrary.ErrorMessage(ErrorLibrary.POLL.NOT_PUBLISHED));
                break;

            case 0:
                throw new Exception(ErrorLibrary.ErrorMessage(ErrorLibrary.POLL.EXPIRED));
                break;
            }

            choice.numberOfVotes += 1;
            choice.lastBuildDate  = DateTime.Now;

            _context.SubmitChanges();
        }
コード例 #3
0
ファイル: FileLibrary.cs プロジェクト: omeryesil/awapicms
        /// <summary>
        /// Add file with URL address
        /// </summary>
        /// <param name="siteId"></param>
        /// <param name="groupIds"></param>
        /// <param name="userId"></param>
        /// <param name="title"></param>
        /// <param name="description"></param>
        /// <param name="fileUrl"></param>
        /// <param name="isEnabled"></param>
        /// <returns></returns>
        public long Add(long siteId, long fileId, long[] groupIds, long userId, string title, string description,
                        string fileUrl, string thumbUrl, bool isEnabled)
        {
            //Check if all the file groups exist---------------
            var groupList = from g in _context.awFileGroups
                            where groupIds.Contains(g.fileGroupId)
                            select g;

            if (groupList == null || groupList.Count() < groupIds.Length)
            {
                throw new Exception("One or more file groups do not exist");
            }

            //Save the file
            awFile file = new awFile();

            file.fileId = fileId > 0 ? fileId : MiscLibrary.CreateUniqueId();

            string resourceFileName = GetFileNameOnly(fileUrl);
            string extension        = GetFileExension(resourceFileName);

            //SAVE THE FILE FIRST
            try
            {
                file.contentType   = GetContentType(AWAPI_BusinessLibrary.library.ConfigurationLibrary.Config.fileMimeXMLPath, extension);
                file.isOnLocal     = false; //this also can be used for external urls (not only amazon)
                file.contentSize   = 0;
                file.path          = fileUrl.ToLower();
                file.siteId        = siteId;
                file.title         = String.IsNullOrEmpty(title) ? resourceFileName : title;
                file.description   = description;
                file.link          = fileUrl.ToLower();
                file.thumbnail     = thumbUrl.ToLower();
                file.pubDate       = DateTime.Now;
                file.lastBuildDate = DateTime.Now;
                file.isEnabled     = isEnabled;
                file.userId        = userId;
                file.createDate    = DateTime.Now;

                _context.awFiles.InsertOnSubmit(file);
                _context.SubmitChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }

            //add file to groups
            AddFileToGroups(file.fileId, groupIds);
            return(file.fileId);
        }
コード例 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="siteTagId"></param>
        /// <param name="fieldId"></param>
        /// <param name="userId"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public long UpdateFieldValue(long contentId, long fieldId, long userId, string value, string cultureCode)
        {
            var flds = from f in _context.awContentCustomFieldValues
                       where f.customFieldId.Equals(fieldId) &&
                       f.contentId.Equals(contentId)
                       select f;

            awContentCustomFieldValue fld = _context.awContentCustomFieldValues.
                                            FirstOrDefault(v => v.customFieldId.Equals(fieldId) &&
                                                           v.contentId.Equals(contentId) &&
                                                           v.cultureCode.Equals(cultureCode));

            //if doesn't exist then Add a new one, else udpate the current one
            if (fld == null)
            {
                fld = new awContentCustomFieldValue();
                fld.customFieldValueId = MiscLibrary.CreateUniqueId();
                fld.cultureCode        = cultureCode;
                fld.customFieldId      = fieldId;
                fld.contentId          = contentId;
                fld.fieldValue         = value;
                fld.userId             = userId;
                fld.lastBuildDate      = DateTime.Now;
                fld.createDate         = DateTime.Now;

                _context.awContentCustomFieldValues.InsertOnSubmit(fld);
            }
            else
            {
                fld.fieldValue    = value;
                fld.userId        = userId;
                fld.lastBuildDate = DateTime.Now;
            }

            _context.SubmitChanges();

            return(fld.customFieldValueId);
        }
コード例 #5
0
ファイル: FileLibrary.cs プロジェクト: omeryesil/awapicms
        /// <summary>
        ///
        /// </summary>
        /// <param name="fileId"></param>
        /// <param name="groupId"></param>
        /// <returns></returns>
        public void AddFileToGroups(long fileId, long[] groupIds)
        {
            //delete file group association
            var tmpList = from fg in _context.awFileInGroups
                          where fg.fileId.Equals(fileId)
                          select fg;

            _context.awFileInGroups.DeleteAllOnSubmit(tmpList);

            foreach (long groupId in groupIds)
            {
                long fileInGroupId = MiscLibrary.CreateUniqueId();

                awFileInGroup file = new awFileInGroup();
                file.fileInGroupId = fileInGroupId;
                file.fileGroupId   = groupId;
                file.fileId        = fileId;
                file.createDate    = DateTime.Now;

                _context.awFileInGroups.InsertOnSubmit(file);
            }
            _context.SubmitChanges();
        }
コード例 #6
0
ファイル: PollLibrary.cs プロジェクト: omeryesil/awapicms
        /// <summary>
        /// Returns poll based on the culturecode
        /// </summary>
        /// <param name="pollId"></param>
        /// <param name="cultureCode"></param>
        /// <returns></returns>
        public AWAPI_Data.CustomEntities.PollExtended GetPoll(long pollId, string cultureCode, bool onlyPublished)
        {
            if (pollId <= 0)
            {
                return(null);
            }
            DateTime now = DateTime.Now;

            AWAPI_Data.CustomEntities.PollExtended poll = (from l in _context.awPolls
                                                           where l.pollId.Equals(pollId) &&
                                                           (!onlyPublished ||
                                                            (onlyPublished && l.isEnabled && l.awSite_Poll.isEnabled))
                                                           select new AWAPI_Data.CustomEntities.PollExtended
            {
                pollId = l.pollId,
                title = l.title,
                description = l.description,
                answeredQuestion = l.answeredQuestion,
                isEnabled = l.isEnabled,
                isPublic = l.isPublic,
                isMultipleChoice = l.isMultipleChoice,
                siteId = l.siteId,
                userId = l.userId,
                pubDate = l.pubDate,
                pubEndDate = l.pubEndDate,
                createDate = l.createDate,
                lastBuildDate = l.lastBuildDate,
                availableToVote = ((l.pubDate.Equals(null) || l.pubDate <= now) &&
                                   (l.pubEndDate.Equals(null) || l.pubEndDate > now)) ? true : false,

                pollChoices = this.GetPollChoiceList(l.pollId, cultureCode),
                siteCultureCode = l.awSite_Poll.cultureCode
            }).FirstOrDefault <AWAPI_Data.CustomEntities.PollExtended>();

            //if (list == null && list.ToList().Count() == 0)
            //   return null;

            //AWAPI_Data.CustomEntities.PollExtended poll = list.FirstOrDefault();
            if (poll == null)
            {
                return(null);
            }

            if (onlyPublished)
            {
                // if not published yet....
                int dateBetween = MiscLibrary.IsDateBetween(DateTime.Now, poll.pubDate, poll.pubEndDate);
                if (dateBetween == 0)
                {
                    return(null);
                }
                //throw new Exception(ErrorLibrary.ErrorMessage(ErrorLibrary.POLL.NOT_PUBLISHED));
            }

            //if site's culture code equals to cultureCode parameter
            if (String.IsNullOrEmpty(cultureCode) || poll.siteCultureCode.ToLower() == cultureCode.ToLower())
            {
                return(poll);
            }

            poll.description      = _cultureLib.GetValue(cultureCode.ToLower(), poll.pollId, "awpoll", "description");
            poll.answeredQuestion = _cultureLib.GetValue(cultureCode.ToLower(), poll.pollId, "awpoll", "answeredQuestion");
            return(poll);
        }