public ActionResult Create()
        {
            WorkContext.Breadcrumbs.Add(new Breadcrumb {
                Text = T("Quản lý tuyển dụng"), Url = "#"
            });
            WorkContext.Breadcrumbs.Add(new Breadcrumb {
                Text = T("Thêm thông tin tuyển dụng"), Url = Url.Action("Index")
            });
            var model = new RecruitmentModel();

            var result = new ControlFormResult <RecruitmentModel>(model);

            result.Title                = this.T("Thêm thông tin tuyển dụng");
            result.FormMethod           = FormMethod.Post;
            result.UpdateActionName     = "Update";
            result.ShowCancelButton     = false;
            result.ShowBoxHeader        = false;
            result.FormWrapperStartHtml = Constants.Form.FormWrapperStartHtml;
            result.FormWrapperEndHtml   = Constants.Form.FormWrapperEndHtml;

            result.AddAction().HasText(this.T("Thêm mới")).HasUrl(this.Url.Action("Create")).HasButtonStyle(ButtonStyle.Success);
            result.AddAction().HasText(this.T("Back")).HasUrl(this.Url.Action("Index")).HasButtonStyle(ButtonStyle.Danger);

            result.RegisterExternalDataSource(x => x.CategoryId, BindCategories());

            return(result);
        }
        private void comboBoxRecruitSelection_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.collectionAgeproRecruitmentModels != null)
            {
                ComboBox modelSelectionCbx = sender as ComboBox;

                labelRecruitSelection.Text = getSelectedRecruitmentModelName(modelSelectionCbx.SelectedIndex);

                RecruitmentModel currentRecruitSelection = this.collectionAgeproRecruitmentModels[modelSelectionCbx.SelectedIndex];

                LoadRecruitModelParameterControls(currentRecruitSelection);
            }
        }
        private void tabControlRecruitment_SelectedIndexChanged(object sender, EventArgs e)
        {
            //When switching to the "Recruit Model" Tab, set up selected model name for labelRecruitSelection
            if ((sender as TabControl).SelectedIndex == 1)
            {
                labelRecruitSelection.Text = getSelectedRecruitmentModelName(comboBoxRecruitSelection.SelectedIndex);

                //Catch for nulls
                if (collectionAgeproRecruitmentModels.Count != 0)
                {
                    RecruitmentModel selectedRecruitModel = collectionAgeproRecruitmentModels[comboBoxRecruitSelection.SelectedIndex];
                    //Load the appropriate panel
                    LoadRecruitModelParameterControls(selectedRecruitModel);
                }
                else
                {
                    panelRecruitModelParameter.Controls.Clear();
                }
            }
        }
        //TODO:REFACTOR
        private void LoadRecruitModelParameterControls(RecruitmentModel currentRecruitSelection)
        {
            if (currentRecruitSelection is EmpiricalRecruitment)
            {
                if (((EmpiricalRecruitment)currentRecruitSelection).subType == EmpiricalType.Empirical)
                {
                    EmpiricalRecruitment currentEmpiricalRecruitSelection = (EmpiricalRecruitment)currentRecruitSelection;

                    ControlRecruitmentEmpirical empiricalParameterControls = new ControlRecruitmentEmpirical();

                    empiricalParameterControls.SetEmpiricalRecruitmentControls(currentEmpiricalRecruitSelection, panelRecruitModelParameter);
                    empiricalParameterControls.collectionAgeproRecruitmentModels = this.collectionAgeproRecruitmentModels;
                    empiricalParameterControls.collectionSelectedIndex           = this.comboBoxRecruitSelection.SelectedIndex;
                }
                else if (((EmpiricalRecruitment)currentRecruitSelection).subType == EmpiricalType.TwoStage)
                {
                    TwoStageEmpiricalRecruitment currentTwoStageEmpiricalRecruitSelection =
                        (TwoStageEmpiricalRecruitment)currentRecruitSelection;

                    //Load TwoStage Controls
                    ControlRecruitmentEmpiricalTwoStage twoStageControls = new ControlRecruitmentEmpiricalTwoStage();
                    twoStageControls.SetTwoStageEmpiricalRecruitmentControls(currentTwoStageEmpiricalRecruitSelection,
                                                                             panelRecruitModelParameter);
                    twoStageControls.collectionAgeproRecruitmentModels = this.collectionAgeproRecruitmentModels;
                    twoStageControls.collectionSelectedIndex           = this.comboBoxRecruitSelection.SelectedIndex;
                }
                else if (((EmpiricalRecruitment)currentRecruitSelection).subType == EmpiricalType.CDFZero)
                {
                    EmpiricalCDFZero currentEmpiricalCDFZeroRecruitmentSelection = (EmpiricalCDFZero)currentRecruitSelection;

                    ControlRecruitmentEmpirical empiricalCDFZeroControls = new ControlRecruitmentEmpirical();

                    empiricalCDFZeroControls.SetEmpiricalCDFZeroRecruitmentControls(
                        currentEmpiricalCDFZeroRecruitmentSelection, panelRecruitModelParameter);
                    empiricalCDFZeroControls.collectionAgeproRecruitmentModels = this.collectionAgeproRecruitmentModels;
                    empiricalCDFZeroControls.collectionSelectedIndex           = this.comboBoxRecruitSelection.SelectedIndex;
                }
                else if (((EmpiricalRecruitment)currentRecruitSelection).subType == EmpiricalType.Fixed)
                {
                    FixedEmpiricalRecruitment currentFixedRecruitmentSelection = (FixedEmpiricalRecruitment)currentRecruitSelection;

                    ControlRecruitmentFixed fixedRecruitmentControls = new ControlRecruitmentFixed();
                    fixedRecruitmentControls.seqYears = this.seqRecruitYears;
                    fixedRecruitmentControls.SetFixedRecruitmentControls(currentFixedRecruitmentSelection, panelRecruitModelParameter);
                    fixedRecruitmentControls.collectionAgeproRecruitmentModels = this.collectionAgeproRecruitmentModels;
                    fixedRecruitmentControls.collectionSelectedIndex           = this.comboBoxRecruitSelection.SelectedIndex;
                }
            }
            else if (currentRecruitSelection is ParametricRecruitment)
            {
                if (((ParametricRecruitment)currentRecruitSelection).subtype == ParametricType.Curve)
                {
                    ParametricCurve currentParametricCurveRecruit = (ParametricCurve)currentRecruitSelection;

                    ControlRecruitmentParametricCurve parametricCurveControls = new ControlRecruitmentParametricCurve();

                    parametricCurveControls.collectionAgeproRecruitmentModels = this.collectionAgeproRecruitmentModels;
                    parametricCurveControls.collectionSelectedIndex           = this.comboBoxRecruitSelection.SelectedIndex;
                    parametricCurveControls.SetParametricRecruitmentControls(currentParametricCurveRecruit, panelRecruitModelParameter);
                }
                else if (((ParametricRecruitment)currentRecruitSelection).subtype == ParametricType.Lognormal)
                {
                    ParametricLognormal currentParametricLognormalRecruit = (ParametricLognormal)currentRecruitSelection;

                    ControlRecruitmentParametricLognormal lognormalControls = new ControlRecruitmentParametricLognormal();

                    lognormalControls.SetParametricRecruitmentControls(currentParametricLognormalRecruit, panelRecruitModelParameter);
                    lognormalControls.collectionAgeproRecruitmentModels = this.collectionAgeproRecruitmentModels;
                    lognormalControls.collectionSelectedIndex           = this.comboBoxRecruitSelection.SelectedIndex;
                }
            }
            else if (currentRecruitSelection is PredictorRecruitment)
            {
                PredictorRecruitment currentPredictorRecruitSelection = (PredictorRecruitment)currentRecruitSelection;

                ControlRecruitmentPredictor predictorParameterControls = new ControlRecruitmentPredictor();

                predictorParameterControls.seqYears = this.seqRecruitYears;
                predictorParameterControls.collectionSelectedIndex           = this.comboBoxRecruitSelection.SelectedIndex;
                predictorParameterControls.collectionAgeproRecruitmentModels = this.collectionAgeproRecruitmentModels;
                predictorParameterControls.SetPredictorRecruitmentcontrols(currentPredictorRecruitSelection, panelRecruitModelParameter);
            }
            else if (currentRecruitSelection is MarkovMatrixRecruitment)
            {
                MarkovMatrixRecruitment currentRecruit = (MarkovMatrixRecruitment)currentRecruitSelection;

                ControlRecruitmentMarkovMatrix markovControls = new ControlRecruitmentMarkovMatrix();

                markovControls.SetRecruitmentControls(currentRecruit, panelRecruitModelParameter);
                markovControls.collectionAgeproRecruitModels = this.collectionAgeproRecruitmentModels;
                markovControls.collectionSelectedIndex       = this.comboBoxRecruitSelection.SelectedIndex;
            }
            else
            {
                panelRecruitModelParameter.Controls.Clear();
            }
        }
        public ActionResult Update(RecruitmentModel model)
        {
            if (!ModelState.IsValid)
            {
                return(new AjaxResult().Alert(T(Constants.Messages.InvalidModel)));
            }

            RecruitmentInfo         recruitmentTemp = null;
            IList <RecruitmentInfo> records         = new List <RecruitmentInfo> {
                new RecruitmentInfo()
            };

            if (model.Id != 0)
            {
                records         = service.GetRecords(x => x.Id == model.Id || x.RefId == model.Id);
                recruitmentTemp = service.GetRecords(x => x.Id == model.Id).FirstOrDefault();
            }

            var languageManager = WorkContext.Resolve <ILanguageManager>();
            var languages       = languageManager.GetActiveLanguages(Constants.ThemeDefault, false);

            if (model.Id != 0)
            {
                if (languages.Count > 0)
                {
                    foreach (var language in languages)
                    {
                        var languageRecord = records.FirstOrDefault(x => x.LanguageCode == language.CultureCode);
                        if (languageRecord == null)
                        {
                            languageRecord = new RecruitmentInfo
                            {
                                LanguageCode = language.CultureCode,
                                RefId        = model.Id
                            };
                            records.Add(languageRecord);
                        }
                    }
                }
            }

            foreach (var record in records)
            {
                record.CategoryId     = model.CategoryId;
                record.FinishDate     = DateTime.ParseExact(model.FinishDate, Extensions.Constants.DateTimeFomat, CultureInfo.InvariantCulture);
                record.CreateDate     = DateTime.Now.Date;
                record.CreateByUser   = WorkContext.CurrentUser.Id;
                record.Company        = string.Empty;
                record.ContactName    = string.Empty;
                record.ContactAddress = string.Empty;
                record.ContactEmail   = string.Empty;
                record.ContactMobile  = string.Empty;
                record.IsDeleted      = false;

                if (string.IsNullOrEmpty(record.LanguageCode))
                {
                    if (recruitmentTemp == null)
                    {
                        var alias = model.Alias;
                        if (string.IsNullOrEmpty(model.Alias))
                        {
                            alias = Utilities.GetAlias(model.Title);
                        }
                        alias = GetAlias(record.Id, alias, alias, "");

                        record.Title    = model.Title;
                        record.Position = model.Position;
                        record.Alias    = alias;
                        record.Summary  = model.Summary;
                        record.Contents = model.Contents;
                        record.TimeWork = model.TimeWork;
                    }
                    else
                    {
                        record.Title    = recruitmentTemp.Title;
                        record.Position = recruitmentTemp.Position;
                        record.Alias    = recruitmentTemp.Alias;
                        record.Summary  = recruitmentTemp.Summary;
                        record.Contents = recruitmentTemp.Contents;
                        record.TimeWork = recruitmentTemp.TimeWork;
                    }
                }
                else
                {
                    if (languages.Count(x => x.CultureCode.Equals(record.LanguageCode)) == 0)
                    {
                        continue;
                    }

                    var values          = Request.Form.AllKeys.ToDictionary(key => key, key => Request.Form[key]);
                    var localizedValues =
                        values.Keys.Where(key => key.Contains("." + record.LanguageCode))
                        .ToDictionary(key => key.Replace("." + record.LanguageCode, ""),
                                      key => Utilities.FixCheckboxValue(values[key]));
                    var nameValueCollection = localizedValues.ToNameValueCollection();

                    record.Title = nameValueCollection.Get("Title");

                    var alias = nameValueCollection.Get("Alias");
                    if (string.IsNullOrEmpty(alias))
                    {
                        alias = Utilities.GetAlias(record.Title);
                    }
                    alias           = GetAlias(record.Id, alias, alias, record.LanguageCode);
                    record.Alias    = alias;
                    record.Position = nameValueCollection.Get("Position");
                    record.Summary  = nameValueCollection.Get("Summary");
                    record.Contents = nameValueCollection.Get("Contents");
                    record.TimeWork = nameValueCollection.Get("TimeWork");
                }

                service.Save(record);

                try
                {
                    if (!string.IsNullOrEmpty(record.LanguageCode))
                    {
                        var serviceCategories = WorkContext.Resolve <ICategoriesService>();
                        serviceCategories.LanguageCode = record.LanguageCode;
                        var searchService = WorkContext.Resolve <ISearchService>();
                        searchService.LanguageCode = record.LanguageCode;
                        searchService.SearchType   = (int)SearchType.Recruitment;
                        if (record.IsDeleted)
                        {
                            if (record.Id > 0)
                            {
                                var obj = searchService.GetByItem(record.Id);
                                searchService.Delete(obj);
                            }
                        }
                        else
                        {
                            serviceCategories.LanguageCode = record.LanguageCode;
                            var cate = serviceCategories.GetRecords(x => x.RefId == record.RefId && x.LanguageCode == record.LanguageCode).FirstOrDefault();
                            var url  = string.Empty;
                            if (cate != null)
                            {
                                url = Url.Action("RecruitmentDetails", "HomeRecruitment", new { cateAlias = cate.Alias, alias = record.Alias });
                            }
                            SearchInfo search = (record.Id > 0 ? searchService.GetByItem(record.Id) : new SearchInfo()) ?? new SearchInfo();
                            search.Alias        = record.Alias;
                            search.CategoryId   = record.CategoryId;
                            search.CreateDate   = DateTime.Now;
                            search.Images       = Extensions.Constants.ImageDefault;
                            search.LanguageCode = record.LanguageCode;
                            search.SearchId     = record.Id.ToString();
                            search.Sumary       = record.Summary;
                            search.Tags         = record.Title;
                            search.Title        = record.Title;
                            search.VideoUrl     = string.Empty;
                            search.Type         = (int)SearchType.Articles;
                            search.Url          = url;
                            searchService.Save(search);
                        }
                    }
                }
                catch (Exception ex)
                {
                    return(new AjaxResult().NotifyMessage("UPDATE_ENTITY_COMPLETE").Alert(ex.Message));
                }
            }

            return(new AjaxResult().NotifyMessage("UPDATE_ENTITY_COMPLETE").Alert(T("Đã cập nhật thành công.")));
        }
        public ActionResult Edit(int id)
        {
            WorkContext.Breadcrumbs.Add(new Breadcrumb {
                Text = T("Quản lý tuyển dụng"), Url = "#"
            });
            WorkContext.Breadcrumbs.Add(new Breadcrumb {
                Text = T("Sửa thông tin tuyển dụng"), Url = Url.Action("Index")
            });

            var records            = service.GetRecords(x => x.Id == id || x.RefId == id);
            RecruitmentModel model = records.First(x => x.Id == id);
            var modelType          = model.GetType();

            if (string.IsNullOrEmpty(model.Contents) || model.Contents.Trim() == "<br />")
            {
                var viewRenderer = new ViewRenderer {
                    Context = ControllerContext
                };
                var viewTemplate = viewRenderer.RenderPartialView(string.Format(Extensions.Constants.ViewRecruitmentTemplate, WorkContext.CurrentCulture), null);
                model.Contents = viewTemplate;
            }

            var result = new ControlFormResult <RecruitmentModel>(model);

            result.Title            = this.T("Sửa thông tin tuyển dụng");
            result.FormMethod       = FormMethod.Post;
            result.Layout           = ControlFormLayout.Tab;
            result.UpdateActionName = "Update";
            result.ShowCancelButton = false;
            result.ShowBoxHeader    = false;

            result.ExcludeProperty(x => x.Alias);
            result.ExcludeProperty(x => x.Contents);
            result.ExcludeProperty(x => x.Position);
            result.ExcludeProperty(x => x.Summary);
            result.ExcludeProperty(x => x.Title);
            result.ExcludeProperty(x => x.TimeWork);

            var mainTab           = result.AddTabbedLayout("Thông tin chính");
            var mainGroup         = mainTab.AddGroup();
            var allFields         = modelType.GetProperties(BindingFlags.Instance | BindingFlags.Public);
            var controlAttributes = new Dictionary <string, ControlFormAttribute>();

            foreach (var propertyInfo in allFields)
            {
                var controlAttribute = propertyInfo.GetCustomAttribute <ControlFormAttribute>(true);
                if (controlAttribute == null)
                {
                    continue;
                }
                mainGroup.Add(propertyInfo.Name);
                controlAttribute.PropertyInfo = propertyInfo;
                controlAttribute.PropertyType = propertyInfo.PropertyType;
                controlAttributes.Add(propertyInfo.Name, controlAttribute);
            }

            var languageManager = WorkContext.Resolve <ILanguageManager>();
            var languages       = languageManager.GetActiveLanguages(Constants.ThemeDefault, false);
            var listHidden      = new List <string>
            {
                "Id", "CategoryId", "IsDeleted", "FinishDate"
            };

            if (languages.Count > 0)
            {
                foreach (var language in languages)
                {
                    var languageTab       = result.AddTabbedLayout(language.Name);
                    var languageGroup     = languageTab.AddGroup();
                    var widgetForLanguage = records.FirstOrDefault(x => x.LanguageCode == language.CultureCode) ?? model;

                    foreach (var controlAttribute in controlAttributes)
                    {
                        if (listHidden.Contains(controlAttribute.Key))
                        {
                            continue;
                        }

                        var key   = controlAttribute.Key + "." + language.CultureCode;
                        var value = controlAttribute.Value.PropertyInfo.GetValue(widgetForLanguage);
                        result.AddProperty(key, controlAttribute.Value.ShallowCopy(), value);
                        languageGroup.Add(key);
                    }
                }
            }
            result.AddAction().HasText(this.T("Thêm mới")).HasUrl(this.Url.Action("Create")).HasButtonStyle(ButtonStyle.Success);
            result.AddAction().HasText(this.T("Back")).HasUrl(this.Url.Action("Index")).HasButtonStyle(ButtonStyle.Danger);

            result.RegisterExternalDataSource(x => x.CategoryId, y => BindCategories());

            return(result);
        }