Ejemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var uow = new EmployeeFinderData();
            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.TotalEmployees.Text = "Total employees: " + Cache["employeesCount"].ToString();
            }
            else
            {
                var employeesCount = uow.Employees.All().Count();
                Cache.Insert("employeesCount", employeesCount, null, DateTime.Now.AddSeconds(50), TimeSpan.Zero);
                this.TotalEmployees.Text = "Total employees: " + employeesCount;
            }

            var employees = uow.Employees.All().OrderBy(x => x.Rating ).ToList();
            this.ListViewEmployees.DataSource = employees;
            this.Page.DataBind();

        }
Ejemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.User == null || !this.User.Identity.IsAuthenticated)
            {
                this.Server.Transfer("~/Account/Login.aspx", true);
            }

            if (!this.IsPostBack)
            {
                foreach (int value in Enum.GetValues(typeof(Position)))
                {
                    this.Possition.Items.Add(new ListItem(Enum.GetName(typeof(Position), value), value.ToString()));
                }

                for (var i = 1; i <= 6; i++)
                {
                    this.Rating.Items.Add(new ListItem(i.ToString()));
                }

                this.Rating.SelectedIndex = 0;

                var db = new EmployeeFinderData();

                this.Page.DataBind();
            }
        }
Ejemplo n.º 3
0
        private void PopulateUserData()
        {
            var uow = new EmployeeFinderData();
            var userId = this.User.Identity.GetUserId();
            var user =
                uow.Users.All()
                    .Select(u => new { u.Id, u.FirstName, u.LastName, u.AvatarUrl })
                    .First(u => u.Id == userId);

            this.Avatar.ImageUrl = GlobalConstants.ImagesPath + user.AvatarUrl;

            this.Page.DataBind();

            this.FirstName.Text = user.FirstName;
            this.LastName.Text = user.LastName;
        }
Ejemplo n.º 4
0
        protected void OnClick(object sender, EventArgs e)
        {
            var uow = new EmployeeFinderData();

            var currentUser = uow.Users.All().FirstOrDefault(x => x.UserName == this.User.Identity.Name);
            var newEmployee = new Employee();
            newEmployee.FirstName = this.FirstName.Text;
            newEmployee.LastName = this.LastName.Text;
            newEmployee.Position = (Position)Enum.Parse(typeof(Position), this.Possition.SelectedValue);
            newEmployee.Rating = this.Rating.SelectedIndex + 1;
            newEmployee.RatingsCount += 1;

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

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

            uow.Employees.Add(newEmployee);
            currentUser.Comments.Add(new Comment { Content = this.Comment.Text, Employee = newEmployee });
            uow.SaveChanges();
            Notifier.Success("Employee offer successfully created");
            this.Response.Redirect("~/Default.aspx");
        }
Ejemplo n.º 5
0
        protected void UpdateAccount_Click(object sender, EventArgs e)
        {
            try
            {
                var data = new EmployeeFinderData();
                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;
                }

                data.SaveChanges();
                Notifier.Success("Account successfully updated");
                this.Response.Redirect("~/Account/Manage.aspx", true);
            }
            catch (Exception err)
            {
                // TODO: this is wrong
                if (err.Message != "Thread was being aborted.")
                {
                    Notifier.Error(err.Message);
                }
            }
        }