コード例 #1
0
        public ActionResult CreateVacancy(MyVacancy vacancy)
        {
            if (!ModelState.IsValid)
            {
                MessageForClient(ActionStatus.Error, $"Указанные данные не валидны.");
                return(RedirectToAction("Index", "Home"));
            }
            var savingVacancy = _mapper.Map <MyVacancy, VacancyBase>(vacancy);
            var identityUser  = _userRepository.FindUser(User.Identity.Name);

            if (identityUser.Status != ActionStatus.Success)
            {
                MessageForClient(ActionStatus.Error, $"Не удалось найти пользователя, которому требуется добавить объявление.");
                return(RedirectToAction("Index", "Home"));
            }
            savingVacancy.Creator    = identityUser.Entity.First() as UserBase;
            savingVacancy.LastEditor = savingVacancy.Creator;
            var updatedResult = _announcementRepository.CreateAnnouncement(savingVacancy);

            MessageForClient(updatedResult.Status, updatedResult.Message);
            if (updatedResult.Status != ActionStatus.Success)
            {
                return(RedirectToAction("Index", "Home"));
            }
            return(RedirectToAction("ShowUser", "User", new { (updatedResult.Entity.First() as VacancyBase).Creator.Login }));
        }
コード例 #2
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            foreach (IValidator i in this.Validators)
            {
                i.Validate();
            }

            if (IsValid)
            {
                MyVacancy my = new MyVacancy();
                my.ProfessionName   = userProfession.Text;
                my.MinSalary        = Convert.ToInt32(txtMinSalary.Text);
                my.MaxSalary        = Convert.ToInt32(txtMaxSalary.Text);
                my.Requirments      = txtReq.Text;
                my.TypeOfEmployment = txtTypeOfEmp.Text;
                my.Description      = txtDesc.Text;
                my.CompanyId        = user.CompanyDetails;
                my.Categories       = vacCategories.Items.OfType <ListItem>().Where(i => i.Selected == true).Select(i1 => i1.Text).ToList();
                my.EmployerName     = user.Surname + " " + user.Name + " " + user.FathersName;
                my.EmployerPhone    = user.Phone;
                my.City             = userCity.SelectedValue;
                my.CreationTime     = DateTime.Now;

                userManager.RegisterVacancy(my);

                Response.Redirect("~/Employer");
            }
        }
コード例 #3
0
ファイル: HomeController.cs プロジェクト: vovanovak/WorkAtUa
        public ActionResult Unsubscribe(int vacId)
        {
            MyUser u = _manager.GetUserByEmail(this.Session["Email"].ToString());

            _manager.UnsubscribeFromVacancy(vacId, u.Id);

            MyVacancy my = _manager.GetVacancyByIdNonSt(vacId);

            ViewBag.Vacancy    = my;
            ViewBag.Subscribed = _manager.IsUserSubscribedForAVacancy(vacId, u.Id);
            string date;

            TimeSpan diff = DateTime.Now.Subtract(my.CreationTime);
            int      days = Convert.ToInt32(diff.TotalDays) - 1;

            if (days == 0)
            {
                date = "today";
            }
            else
            if (days == 1)
            {
                date = "yesterday";
            }
            else
            {
                date = Convert.ToInt32(diff.TotalDays).ToString() + " days ago";
            }
            ViewBag.CurrentUser = u;
            ViewBag.Date        = date;
            ViewBag.Comments    = _manager.GetCommentsByVacancyId(my.Id);

            return(View("Item"));
        }
コード例 #4
0
        public ActionResult EditVacancy(MyVacancy editingVacancy)
        {
            if (!ModelState.IsValid)
            {
                MessageForClient(ActionStatus.Error, $"Указанные данные не валидны.");
                return(RedirectToAction("Index", "Home"));
            }
            var repositoryResult = _announcementRepository.FindAnnouncement(editingVacancy.Id);

            if (repositoryResult.Status != ActionStatus.Success)
            {
                MessageForClient(repositoryResult.Status, repositoryResult.Message);
                return(RedirectToAction("Index", "Home"));
            }
            if ((repositoryResult.Entity.First() as VacancyBase).Creator.Login != User.Identity.Name && !User.IsInRole("Admin"))
            {
                MessageForClient(ActionStatus.Error, "У вас недостаточно прав для редактирования данного объявления!");
                return(RedirectToAction("ShowAnnouncement", "Announcement", new { editingVacancy.Id }));
            }
            repositoryResult = _userRepository.FindUser(User.Identity.Name);
            if (repositoryResult.Status != ActionStatus.Success)
            {
                MessageForClient(repositoryResult.Status, $"Не найден авторизованный пользователь ({User.Identity.Name}).");
                return(RedirectToAction("Index", "Home"));
            }
            var updatingVacancy = _mapper.Map <MyVacancy, VacancyBase>(editingVacancy);

            updatingVacancy.LastEditor = repositoryResult.Entity.First() as UserBase;
            repositoryResult           = _announcementRepository.UpdateAnnouncement(updatingVacancy);
            MessageForClient(repositoryResult.Status, repositoryResult.Message);

            return(repositoryResult.Status == ActionStatus.Success
                ? RedirectToAction("ShowAnnouncement", "Announcement", new { (repositoryResult.Entity.First() as VacancyBase).Id })
                : RedirectToAction("Index", "Home"));
        }
コード例 #5
0
        public void AddVacancyInCategory(MyVacancy my)
        {
            foreach (var i in my.Categories)
            {
                ctx.VacancyInCategories.Add(new VacancyInCategory()
                {
                    CategoryId = GetCategoryIdByName(i), VacancyId = my.Id
                });
            }

            ctx.SaveChanges();
        }
コード例 #6
0
        public object GetPropertyValue(MyVacancy my, string name)
        {
            PropertyInfo[] properties = my.GetType().GetProperties();

            foreach (var i in properties)
            {
                if (i.Name == name)
                {
                    return(i.GetValue(my));
                }
            }

            return(null);
        }
コード例 #7
0
        public static MyVacancy VacToMy(Vacancy v)
        {
            MyVacancy my = new MyVacancy();

            my.Id               = v.Id;
            my.ProfessionName   = v.ProfessionName;
            my.MinSalary        = v.MinSalary;
            my.MaxSalary        = v.MaxSalary;
            my.Requirments      = v.Requirments;
            my.TypeOfEmployment = v.TypeOfEmployment;
            my.Description      = v.Description;
            my.EmployerName     = v.EmployerName;
            my.EmployerPhone    = v.EmployerPhone;
            my.City             = v.City;
            my.CompanyId        = v.CompanyId;
            my.CreationTime     = v.CreationTime.Value;
            my.IsSolved         = v.IsSolved;

            return(my);
        }
コード例 #8
0
ファイル: HomeController.cs プロジェクト: vovanovak/WorkAtUa
        public ActionResult Search(int id)
        {
            MyVacancy my = _manager.GetVacancyByIdNonSt(id);

            ViewBag.Vacancy = my;

            string date;



            TimeSpan diff = DateTime.Now.Subtract(my.CreationTime);
            int      days = Convert.ToInt32(diff.TotalDays) - 1;

            if (days == 0)
            {
                date = "today";
            }
            else
            if (days == 1)
            {
                date = "yesterday";
            }
            else
            {
                date = Convert.ToInt32(diff.TotalDays).ToString() + " days ago";
            }

            ViewBag.Date        = date;
            ViewBag.CurrentUser = this.Session["CurrentUser"];
            if (ViewBag.CurrentUser != null)
            {
                ViewBag.Subscribed = _manager.IsUserSubscribedForAVacancy(ViewBag.CurrentUser.Id, id);
            }
            ViewBag.Comments = _manager.GetCommentsByVacancyId(my.Id);

            return(View("Item"));
        }
コード例 #9
0
        public void RegisterVacancy(MyVacancy my)
        {
            Vacancy vac = new Vacancy();

            vac.ProfessionName   = my.ProfessionName;
            vac.MinSalary        = my.MinSalary;
            vac.MaxSalary        = my.MaxSalary;
            vac.CompanyId        = my.CompanyId;
            vac.Requirments      = my.Requirments;
            vac.TypeOfEmployment = my.TypeOfEmployment;
            vac.Description      = my.Description;
            vac.EmployerName     = my.EmployerName;
            vac.EmployerPhone    = my.EmployerPhone;
            vac.City             = my.City;
            vac.CreationTime     = my.CreationTime;
            vac.IsSolved         = my.IsSolved;

            ctx.Vacancies.Add(vac);
            ctx.SaveChanges();

            my.Id = ctx.Vacancies.Max(v => v.Id);

            AddVacancyInCategory(my);
        }
コード例 #10
0
        protected void repUsers_ItemCommand1(object source, RepeaterCommandEventArgs e)
        {
            #region Delete
            if (e.CommandName == "Delete")
            {
                int id = Convert.ToInt32(e.CommandArgument);
                rep.Delete(id);
                UpdateData();
            }
            #endregion

            #region Edit
            if (e.CommandName == "Edit")
            {
                int id = Convert.ToInt32(e.CommandArgument);


                MyVacancy my = rep.GetEntityById(id) as MyVacancy;

                for (int i = 0; i < e.Item.Controls.Count; i++)
                {
                    TextBox t = e.Item.Controls[i] as TextBox;
                    if (t != null)
                    {
                        t.Style.Add("display", "block");
                        t.Text = GetPropertyValue(my, t.ToolTip).ToString();
                    }
                    else
                    {
                        DropDownList lst = e.Item.Controls[i] as DropDownList;

                        if (lst != null)
                        {
                            lst.Style.Add("display", "block");
                            List <MyCompanyDetail> companies = repCompanies.GetAll();
                            lst.DataSource = companies.Select(c => c.Name);
                            lst.DataBind();

                            string name = DBManager.DbManager.GetCompanyNameById(my.CompanyId);

                            lst.SelectedValue = (name == null) ? lst.Items[0].Value : name;
                        }
                    }
                }

                int index = -1;
                for (int i = 0; i < repVacancies.Items.Count; i++)
                {
                    if (repVacancies.Items[i] == e.Item)
                    {
                        index = i;
                    }
                }

                ViewState.Add("EditedId", id);
                ViewState.Add("EditedIndex", index);

                btnSave.Style.Add("display", "inline");
                btnCancel.Style.Add("display", "inline");

                isEditing = true;
            }
            #endregion

            #region Add

            if (e.CommandName == "Add")
            {
                List <MyVacancy> users = rep.GetAll();
                MyVacancy        my    = new MyVacancy();
                users.Add(my);

                repVacancies.DataSource = users;
                repVacancies.DataBind();

                RepeaterItem item = repVacancies.Items.OfType <RepeaterItem>().ElementAt(repVacancies.Items.Count - 1);

                for (int i = 0; i < item.Controls.Count; i++)
                {
                    TextBox t = item.Controls[i] as TextBox;
                    if (t != null)
                    {
                        t.Style.Add("display", "block");
                        object obj = GetPropertyValue(my, t.ToolTip);
                        t.Text = (obj == null) ? "" : obj.ToString();
                    }
                    else
                    {
                        DropDownList lst = item.Controls[i] as DropDownList;

                        if (lst != null)
                        {
                            lst.Style.Add("display", "block");
                            List <MyCompanyDetail> companies = repCompanies.GetAll();
                            lst.DataSource = companies.Select(c => c.Name);
                            lst.DataBind();

                            lst.SelectedValue = lst.Items[0].Value;
                        }
                    }
                }

                int index = -1;
                for (int i = 0; i < repVacancies.Items.Count; i++)
                {
                    if (repVacancies.Items[i] == item)
                    {
                        index = i;
                    }
                }

                ViewState.Add("EditedId", -1);
                ViewState.Add("EditedIndex", index);

                btnSave.Style.Add("display", "inline");
                btnCancel.Style.Add("display", "inline");

                isEditing = true;
            }

            #endregion
        }
コード例 #11
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            this.Validate();

            int index = Convert.ToInt32(ViewState["EditedIndex"]);
            int id    = Convert.ToInt32(ViewState["EditedId"]);

            RepeaterItem item = repVacancies.Items[index];
            MyVacancy    my   = new MyVacancy();

            if (id != -1)
            {
                my = rep.GetEntityById(id) as MyVacancy;
            }

            for (int i = 0; i < item.Controls.Count; i++)
            {
                TextBox t = item.Controls[i] as TextBox;
                if (t != null)
                {
                    string propName = t.ToolTip;

                    switch (propName)
                    {
                    case "ProfessionName":
                        if (my.ProfessionName != t.Text)
                        {
                            my.ProfessionName = t.Text;
                        }
                        break;

                    case "EmployerName":
                        if (my.EmployerName != t.Text)
                        {
                            my.EmployerName = t.Text;
                        }
                        break;

                    case "EmployerPhone":
                        if (my.EmployerPhone != t.Text)
                        {
                            my.EmployerPhone = t.Text;
                        }
                        break;

                    case "MinSalary":
                        if (my.MinSalary != Convert.ToDecimal(t.Text))
                        {
                            my.MinSalary = Convert.ToDecimal(t.Text);
                        }
                        break;

                    case "MaxSalary":
                        if (my.MaxSalary != Convert.ToDecimal(t.Text))
                        {
                            my.MaxSalary = Convert.ToDecimal(t.Text);
                        }
                        break;

                    case "Requirments":
                        if (my.Requirments != t.Text)
                        {
                            my.Requirments = t.Text;
                        }
                        break;

                    case "TypeOfEmployment":
                        if (my.TypeOfEmployment != t.Text)
                        {
                            my.TypeOfEmployment = t.Text;
                        }
                        break;

                    case "Description":
                        if (my.Description != t.Text)
                        {
                            my.Description = t.Text;
                        }
                        break;

                    default:
                        break;
                    }

                    t.Style.Add("display", "none");
                }
                else
                {
                    DropDownList lst = item.Controls[i] as DropDownList;

                    if (lst != null)
                    {
                        int val = DBManager.DbManager.GetCompanyIdByName(lst.SelectedValue);
                        if (my.CompanyId != val)
                        {
                            my.CompanyId = val;
                        }

                        lst.Style.Add("display", "none");
                    }
                }
            }

            rep.Save(my);

            ViewState.Add("EditedId", -1);
            ViewState.Add("EditedIndex", -1);

            btnSave.Style.Add("display", "none");
            btnCancel.Style.Add("display", "none");

            isEditing = false;

            UpdateData();
        }