Exemplo n.º 1
0
        protected void BtnCreateEvent_Click(object sender, EventArgs e)
        {
            var author = this.User.Identity.GetUserId();

            if (author == null)
            {
                var err = new CustomValidator();
                err.IsValid = false;
                err.ErrorMessage = "You are not logged in!";
                this.Page.Validators.Add(err);
            }

            var newEvent = new Event()
            {
                AuthorId = author,
                Description = this.tbDescription.Text,
                Name = this.tbName.Text,
                DateCreated = DateTime.Now,
                CategoryId = int.Parse(this.DropDownCategories.SelectedValue)
            };

            if (!string.IsNullOrEmpty(this.dtEventStart.Text))
            {
                DateTime startDate;

                if (DateTime.TryParse(this.dtEventStart.Text, out startDate))
                {
                    newEvent.DateTimeStarts = startDate;
                }
            }
 
            if (this.EventImage.HasFile)
            {
                string filename = Path.GetFileName(this.EventImage.FileName);
                var extension = filename.Substring(filename.LastIndexOf('.') + 1);
                if (!ValidationConstants.AllowedExtensions.Contains(extension))
                {
                    var err = new CustomValidator();
                    err.IsValid = false;
                    err.ErrorMessage = "Please upload image with allowed extension (png/jpg/gif/bmp)!";
                    this.Page.Validators.Add(err);
                    return;
                }

                var imagesPath = this.Server.MapPath("~/Public/EventImages/");

                if (!Directory.Exists(imagesPath))
                {
                    Directory.CreateDirectory(imagesPath);
                }

                this.EventImage.SaveAs(imagesPath + filename);
                newEvent.ImageLocation = "/Public/EventImages/" + filename;
            }

            this.db.Events.Add(newEvent);
            this.db.SaveChanges();

            this.Response.Redirect("~/Home");
        }
Exemplo n.º 2
0
        protected int GetCurrentUserVote(Event item)
        {
            string userID = this.User.Identity.GetUserId();
            Like like = item.Likes.FirstOrDefault(l => l.UserID == userID);
            if (like == null)
            {
                return 0;
            }

            return like.Value;
        }
Exemplo n.º 3
0
        protected int GetLikes(Event item)
        {
            if (item.Likes.Count > 0)
            {
                return item.Likes.Sum(l => l.Value);
            }

            return 0;
        }
Exemplo n.º 4
0
 protected string GetName(Event currentEvent)
 {
     return string.Format("{0}", this.Server.HtmlEncode(currentEvent.Name));
 }