Beispiel #1
0
        public Poll AddPoll(string PollName)
        {
            var q = from _poll in PollsData.Polls
                    where _poll.DisplayText == PollName
                    select _poll;

            if (q.Count() > 0)
            {
                return(null);
            }

            Poll poll = new Poll
            {
                DisplayText  = PollName,
                UniqueName   = StringUtils.ToURL(PollName),
                Status       = (int)lw.CTE.Enum.Status.Pending,
                IsDefault    = false,
                DateCreated  = System.DateTime.Now,
                DateModified = System.DateTime.Now
            };

            PollsData.Polls.InsertOnSubmit(poll);
            PollsData.SubmitChanges();

            return(poll);
        }
Beispiel #2
0
        public void UpdatePoll(int PollId, string DisplayText,
                               Status stat,
                               string Category, short?Difficulty, string Reference,
                               short?Day, short?Week, short?Year,
                               HttpPostedFile Picture, bool DeleteOldPicture,
                               string AdditionalText, int?PollNbr, bool IsDefault,
                               bool?Can_Have_Other, string OtherText)
        {
            Poll poll = GetPoll(PollId);

            if (poll == null)
            {
                return;
            }

            poll.DisplayText    = DisplayText;
            poll.Category       = Category;
            poll.Difficulty     = Difficulty;
            poll.Reference      = Reference;
            poll.Day            = Day;
            poll.Week           = Week;
            poll.Year           = Year;
            poll.AdditionalText = AdditionalText;
            poll.PollNbr        = PollNbr;
            poll.IsDefault      = IsDefault;
            poll.Status         = (int)stat;
            poll.DateModified   = System.DateTime.Now;
            poll.Can_Have_Other = Can_Have_Other;
            poll.Other_Text     = OtherText;

            if (IsDefault)
            {
                string sql = string.Format("Update Polls set IsDefault=0 where PollID<>{0}", PollId);
                DBUtils.ExecuteQuery(sql, "NewsManager");
            }

            if (DeleteOldPicture)
            {
                poll.Picture = "";
            }

            string path = WebContext.Server.MapPath(Path.Combine(WebContext.StartDir, ImagesFolder));

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            var oldImage = poll.Picture;

            if (Picture != null && Picture.ContentLength > 0)
            {
                DeleteOldPicture = true;

                string ImageName = Path.GetFileNameWithoutExtension(Picture.FileName);
                ImageName = string.Format("{0}_{1}{2}", ImageName, poll.PollID,
                                          Path.GetExtension(Picture.FileName));

                string _path = Path.Combine(path, ImageName);

                Picture.SaveAs(_path);

                if (ImageName == poll.Picture)
                {
                    DeleteOldPicture = false;
                }

                poll.Picture = ImageName;
            }

            if (DeleteOldPicture && !string.IsNullOrEmpty(oldImage))
            {
                path = Path.Combine(path, oldImage);
                if (File.Exists(path))
                {
                    File.Delete(path);
                }
            }

            PollsData.SubmitChanges();
        }