private void PopulateUserData()
        {
            var uow    = new BarterSystemData();
            var userId = this.User.Identity.GetUserId();
            var user   =
                uow.Users.All()
                .Select(u => new { u.Id, u.FirstName, u.LastName, u.AvatarUrl, u.Skills, u.Rating })
                .First(u => u.Id == userId);

            this.Avatar.ImageUrl   = GlobalConstants.ImagesPath + user.AvatarUrl;
            this.Skills.DataSource = uow.Categories.All().Select(c => c.Name).ToList();
            this.Page.DataBind();

            foreach (var skill in user.Skills)
            {
                var item = this.Skills.Items.FindByValue(skill.Name);
                if (item != null)
                {
                    item.Selected = true;
                }
            }

            this.FirstName.Text = user.FirstName;
            this.LastName.Text  = user.LastName;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.User == null || !this.User.Identity.IsAuthenticated)
            {
                Server.Transfer("~/Account/Login.aspx", true);
            }

            var uow      = new BarterSystemData();
            var userId   = this.User.Identity.GetUserId();
            var username = this.User.Identity.GetUserName();

            this.ListViewBarters.DataSource = uow.Advertisments
                                              .All()
                                              .Where(a => (a.AcceptUserId == userId && !a.CommentedByAcceptUser) || (a.UserId == userId && !a.CommentedByUser) && a.Status == Status.AwaitingFeedback)
                                              .OrderByDescending(a => a.CreationDate)
                                              .Select(a => new BarterForCommentViewModel()
            {
                UserName     = username,
                Content      = a.Content,
                Title        = a.Title,
                Id           = a.Id,
                ImageUrl     = GlobalConstants.ImagesPath + a.ImageUrl,
                CreationDate = a.CreationDate
            })
                                              .ToList();

            Page.DataBind();
        }
Exemple #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.User == null || !this.User.Identity.IsAuthenticated)
            {
                Server.Transfer("~/Account/Login.aspx", true);
            }

            var paramId = Request.QueryString["id"];

            if (paramId == null)
            {
                Response.Redirect("~/");
            }

            if (!IsPostBack)
            {
                var itemNames = System.Enum.GetNames(typeof(BarterSystem.Models.Enums.Feedback));
                var sorted    = itemNames.ToList().OrderByDescending(a => a);
                this.FeedbackType.DataSource = sorted;
                var barterId        = int.Parse(paramId);
                var uow             = new BarterSystemData();
                var commentedBarter = uow.Advertisments.Find(barterId);
                this.BarterTitle.Text   = Server.HtmlEncode(commentedBarter.Title);
                this.BarterAuthor.Text  = commentedBarter.User.UserName;
                this.Photo.ImageUrl     = GlobalConstants.ImagesPath + commentedBarter.ImageUrl;
                this.barterContent.Text = "Content: " + commentedBarter.Content;
                Page.DataBind();
            }
        }
Exemple #4
0
        public IQueryable <AdvertismentViewModel> DisplayBartersGetData()
        {
            var data   = new BarterSystemData();
            var userId = this.User.Identity.GetUserId();
            var ads    = data.Advertisments.All().Where(a => a.UserId == userId || a.AcceptUserId == userId).Select(AdvertismentViewModel.FromAdvertisment);

            return(ads);
        }
Exemple #5
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (this.User == null || !this.User.Identity.IsAuthenticated || !Roles.IsUserInRole("admin"))
     {
         Server.Transfer("~/Account/Login.aspx", true);
     }
     data = new BarterSystemData();
 }
        protected void CreateBarter_Click(object sender, EventArgs e)
        {
            try
            {
                var uow   = new BarterSystemData();
                var newAd = new Advertisment();
                newAd.Title                 = this.TitleAd.Text;
                newAd.Content               = this.Content.Text;
                newAd.CategoryId            = uow.Categories.All().FirstOrDefault(c => c.Name == this.Category.SelectedValue).Id;
                newAd.UserId                = this.User.Identity.GetUserId();
                newAd.Status                = Status.Unapproved;
                newAd.CreationDate          = DateTime.Now;
                newAd.CommentedByUser       = false;
                newAd.CommentedByAcceptUser = false;

                if (this.FileUploadImage.HasFile)
                {
                    if (this.FileUploadImage.PostedFile.ContentLength > 1024000)
                    {
                        Notifier.Error("File has to be less than 1MB");
                        return;
                    }
                    else
                    {
                        string fileName      = this.FileUploadImage.PostedFile.FileName;
                        var    fileExtension = fileName.Substring(fileName.LastIndexOf('.'));
                        var    newName       = Guid.NewGuid() + fileExtension;
                        this.FileUploadImage.SaveAs(Server.MapPath(GlobalConstants.ImagesPath + newName));

                        newAd.ImageUrl = newName;
                    }
                }
                else if (this.ControlImageUrl.HaveUrl())
                {
                    var imageName = Guid.NewGuid().ToString();
                    var filePath  = Server.MapPath(GlobalConstants.ImagesPath + imageName);
                    var extension = this.ControlImageUrl.DownloadRemoteImageFile(filePath);
                    imageName      = imageName + '.' + extension;
                    newAd.ImageUrl = imageName;
                }
                else
                {
                    newAd.ImageUrl = GlobalConstants.DefautlBarterImg;
                }

                uow.Advertisments.Add(newAd);
                uow.SaveChanges();
                Notifier.Success("Barter offer successfully created");
                Response.Redirect("~/Barter/Create");
            }
            catch (Exception er)
            {
                if (er.Message != "Thread was being aborted.")
                {
                    Notifier.Error(er.Message);
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.User == null || !this.User.Identity.IsAuthenticated)
            {
                Server.Transfer("~/Account/Login.aspx", true);
            }

            if (!IsPostBack)
            {
                var uow = new BarterSystemData();
                this.Category.DataSource = uow.Categories.All().Select(c => c.Name).ToList();
                Page.DataBind();
            }
        }
Exemple #8
0
        private void BindData()
        {
            var data   = new BarterSystemData();
            var userId = this.User.Identity.GetUserId();

            this.UserModel       = data.Users.All().Where(u => u.Id == userId).Select(UserViewModel.FromDataToModel).First();
            this.Avatar.ImageUrl = GlobalConstants.ImagesPath + this.UserModel.AvatarUrl;
            this.Username.Text   = Server.HtmlEncode(this.UserModel.Username);
            this.Name.Text       = Server.HtmlEncode(string.Format("{0} {1}", this.UserModel.FirstName, this.UserModel.LastName));
            this.NameHeader.Text = Server.HtmlEncode(string.Format("{0} {1}", this.UserModel.FirstName, this.UserModel.LastName));
            this.Rating.Text     = Server.HtmlEncode(this.UserModel.Rating.ToString(CultureInfo.InvariantCulture));

            this.Skills.DataSource = this.UserModel.Skills;
            this.Skills.DataBind();

            this.Comments.DataSource = this.UserModel.Comments.ToList();
            this.Comments.DataBind();
        }
        protected void UpdateAccount_Click(object sender, EventArgs e)
        {
            try
            {
                var data   = new BarterSystemData();
                var userId = this.User.Identity.GetUserId();
                var user   = data.Users.Find(userId);

                if (this.FirstName.Text != user.FirstName)
                {
                    user.FirstName = this.FirstName.Text;
                }

                if (this.LastName.Text != user.LastName)
                {
                    user.LastName = this.LastName.Text;
                }

                foreach (ListItem item in this.Skills.Items)
                {
                    var skill = data.Categories.All().First(s => s.Name == item.Value);
                    if (item.Selected)
                    {
                        user.Skills.Add(skill);
                    }
                    else
                    {
                        user.Skills.Remove(skill);
                    }
                }

                data.SaveChanges();
                Notifier.Success("Account successfully updated");
                Response.Redirect("~/Account/Manage.aspx", true);
            }
            catch (Exception err)
            {
                // TODO: this is wrong
                if (err.Message != "Thread was being aborted.")
                {
                    Notifier.Error(err.Message);
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.User == null || !this.User.Identity.IsAuthenticated)
            {
                Server.Transfer("~/Account/Login.aspx", true);
            }

            if (!this.Page.IsPostBack)
            {
                if (!string.IsNullOrEmpty(Request.QueryString["id"]))
                {
                    var data   = new BarterSystemData();
                    var userId = Request.QueryString["id"];
                    var user   = data.Users.All().Where(u => u.Id == userId).Select(UserViewModel.FromDataToModel).FirstOrDefault();
                    if (user == null)
                    {
                        Notifier.Warning("User not found");
                        Response.Redirect("~/Default.aspx", true);
                    }
                    else
                    {
                        this.Avatar.ImageUrl = GlobalConstants.ImagesPath + user.AvatarUrl;
                        this.Username.Text   = Server.HtmlEncode(user.Username);
                        this.Name.Text       = Server.HtmlEncode(string.Format("{0} {1}", user.FirstName, user.LastName));
                        this.NameHeader.Text = Server.HtmlEncode(string.Format("{0} {1}", user.FirstName, user.LastName));
                        this.Rating.Text     = Server.HtmlEncode(user.Rating.ToString(CultureInfo.InvariantCulture));

                        this.Skills.DataSource = user.Skills;
                        this.Skills.DataBind();

                        this.Comments.DataSource = user.Comments;
                        this.Comments.DataBind();
                    }
                }
                else
                {
                    Notifier.Error("User not found");
                    Response.Redirect("~/Default.aspx", true);
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            var uow = new BarterSystemData();

            if (Cache["usersCount"] != null)
            {
                this.TotalUsers.Text = "Registered Users: " + Cache["usersCount"].ToString();
            }
            else
            {
                var usersCount = uow.Users.All().Count();
                Cache.Insert("usersCount", usersCount, null, DateTime.Now.AddSeconds(50), TimeSpan.Zero);
                this.TotalUsers.Text = "Registered Users: " + usersCount;
            }

            if (Cache["categoriesCount"] != null)
            {
                this.TotalCategories.Text = "Total categories: " + Cache["categoriesCount"].ToString();
            }
            else
            {
                var categoriesCount = uow.Categories.All().Count();
                Cache.Insert("categoriesCount", categoriesCount, null, DateTime.Now.AddSeconds(50), TimeSpan.Zero);
                this.TotalCategories.Text = "Total categories: " + categoriesCount;
            }

            if (Cache["bartersCount"] != null)
            {
                this.TotalBarters.Text = "Offered barters: " + Cache["bartersCount"].ToString();
            }
            else
            {
                var bartersCount = uow.Advertisments.All().Count();
                Cache.Insert("bartersCount", bartersCount, null, DateTime.Now.AddSeconds(50), TimeSpan.Zero);
                this.TotalBarters.Text = "Offered barters: " + bartersCount;
            }
        }
Exemple #12
0
        public static void Main()
        {
            var dbContext = new BarterSystemData();

            dbContext.Advertisments.All().Any();
        }
 public IList <Category> GetCategoriesWithValues()
 {
     data = new BarterSystemData();
     return(data.Categories.All().ToList());
 }
Exemple #14
0
        protected void Save_Click(object sender, EventArgs e)
        {
            var paramId = Request.QueryString["id"];

            if (paramId == null)
            {
                Response.Redirect("~/");
            }

            var barterId        = int.Parse(paramId);
            var uow             = new BarterSystemData();
            var commentedBarter = uow.Advertisments.Find(barterId);
            var userId          = this.User.Identity.GetUserId();

            if ((commentedBarter.AcceptUserId == userId && !commentedBarter.CommentedByAcceptUser ||
                 commentedBarter.UserId == userId && !commentedBarter.CommentedByUser) && commentedBarter.Status == Status.AwaitingFeedback)
            {
                if (commentedBarter.AcceptUserId == this.User.Identity.GetUserId())
                {
                    commentedBarter.CommentedByAcceptUser = true;
                }
                else
                {
                    commentedBarter.CommentedByUser = true;
                }

                if (commentedBarter.CommentedByUser && commentedBarter.CommentedByAcceptUser)
                {
                    commentedBarter.Status = Status.Done;
                }

                var comment  = new BarterSystem.Models.Comment();
                var selected = this.FeedbackType;
                comment.Feedback = (Feedback)Enum.Parse(typeof(Feedback), selected.Text);
                comment.Content  = this.Content.Text;
                if (commentedBarter.UserId == userId)
                {
                    comment.UserId = commentedBarter.AcceptUserId;
                }
                else
                {
                    comment.UserId = commentedBarter.UserId;
                }

                var user = uow.Users.Find(comment.UserId);
                if (comment.Feedback == Feedback.Positive)
                {
                    user.Rating++;
                }
                else if (comment.Feedback == Feedback.Negative)
                {
                    user.Rating--;
                }

                uow.Users.Update(user);
                uow.Comments.Add(comment);
                uow.SaveChanges();

                Notifier.Success("Barter offer successfully commented");
                Response.Redirect("~/Barter/Comment");
            }
            else
            {
                Notifier.Error("Barter could not be commented");
                Response.Redirect("~/");
            }
        }