public ActionResult SeaBased(List<SeaBasedViewModel> item, IEnumerable<long> remove_exp)
        {
            try
            {
                List<SeaBasedViewModel> modelAdd = new List<SeaBasedViewModel>();
                List<SeaBasedViewModel> modelUpdate = new List<SeaBasedViewModel>();

                int index = 0;
                foreach (var model in item)
                {
                    // GHOST INDEX ?
                    ModelState.Remove("[" + index + "]");
                    index++;
                    // CHECK IF UPDATE OR ADD
                    if (model.id == 0)
                    {
                        modelAdd.Add(model);
                    }
                    else
                    {
                        modelUpdate.Add(model);
                    }
                }

                if (ModelState.IsValid)
                {
                    SeaBasedCollectionViewModel model = new SeaBasedCollectionViewModel();
                    model.add = modelAdd;
                    model.update = modelUpdate;
                    model.remove = remove_exp;
                    model.applicant = UserHelpers.GetUser();

                    SetRequestURL(APIURL.APPLICANT_UPDATE_SEABASED, Method.POST);
                    request.AddBody(model);

                    var response = rest.Execute(request);

                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        Session["MESSAGE"] = new CustomException(Success.EXPERIENCE_UPDATE, MESSAGE_TYPE.SUCCESS);
                        return RedirectToAction("ExperienceInfo");
                    }
                    else
                    {
                        ModelState.AddModelError("", JsonConvert.DeserializeObject<CustomException>(response.Content).Message);
                    }
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex);
            }

            SetRequestURL(APIURL.SEABASED_SELECT_LISTS, Method.GET);
            var res = rest.Execute(request);

            if (res.StatusCode == HttpStatusCode.OK)
            {
                ViewBag.ActiveExperience = "active";
                ViewBag.LandBased = "";
                ViewBag.SeaBased = "active";
                SelectCollectionsViewModel data = JsonConvert.DeserializeObject<SelectCollectionsViewModel>(res.Content);

                foreach (var i in item)
                {
                    i.lstSpecializations = new System.Web.Mvc.SelectList(data.Specializations, "id", "description", i.specialization);
                    i.lstCurrencies = new System.Web.Mvc.SelectList(data.Currencies, "id", "description", i.salary_currency);
                    i.lstVesselTypes = new System.Web.Mvc.SelectList(data.Vessels, "id", "description", i.vessel_type);
                    i.lstTradeAreas = new System.Web.Mvc.SelectList(data.TradeAreas, "id", "description", i.trade_area);
                    i.lstEngineTypes = new System.Web.Mvc.SelectList(data.EngineTypes, "id", "description", i.engine_type);
                }

                return View(item);
            }
            else
            {
                return CustomMessage(res.Content);
            }
        }
        public ActionResult LandBased(List<LandBasedViewModel> item, IEnumerable<long> remove_exp)
        {
            try
            {
                List<LandBasedViewModel> modelAdd = new List<LandBasedViewModel>();
                List<LandBasedViewModel> modelUpdate = new List<LandBasedViewModel>();

                int index = 0;
                foreach (var model in item)
                {
                    if (model.currently_employed == true)
                    {
                        model.employment_to = null;
                        ModelState.Remove("[" + index + "].employment_to");
                    }

                    ModelState.Remove("[" + index + "]");

                    index++;

                    // CHECK IF UPDATE OR ADD
                    if (model.id == 0)
                    {
                        modelAdd.Add(model);
                    }
                    else
                    {
                        modelUpdate.Add(model);
                    }
                }

                if (ModelState.IsValid)
                {
                    LandBasedCollectionViewModel model = new LandBasedCollectionViewModel();
                    model.add = modelAdd;
                    model.update = modelUpdate;
                    model.remove = remove_exp;
                    model.applicant = UserHelpers.GetUser();

                    SetRequestURL(APIURL.APPLICANT_UPDATE_LANDBASED, Method.POST);
                    request.AddBody(model);

                    var response = rest.Execute(request);

                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        Applicant user = JsonConvert.DeserializeObject<Applicant>(response.Content);

                        Session["MESSAGE"] = new CustomException(Success.EXPERIENCE_UPDATE, MESSAGE_TYPE.SUCCESS);
                        if (user.registration_step == Constants.REG_STEP_SEA)
                        {
                            return RedirectToAction("SeaBased");
                        }
                        else
                        {
                            return RedirectToAction("ExperienceInfo");
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", JsonConvert.DeserializeObject<CustomException>(response.Content).Message);
                    }
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex);
            }

            SetRequestURL(APIURL.LANDBASED_SELECT_LISTS, Method.GET);
            var res = rest.Execute(request);

            if (res.StatusCode == HttpStatusCode.OK)
            {
                ViewBag.ActiveExperience = "active";
                ViewBag.LandBased = "active";
                ViewBag.SeaBased = "";
                SelectCollectionsViewModel data = JsonConvert.DeserializeObject<SelectCollectionsViewModel>(res.Content);

                foreach (var i in item)
                {
                    i.lstCountries = new SelectList(data.Countries, "id", "name", i.country);
                    i.lstCurrencies = new SelectList(data.Currencies, "id", "description", i.salary_currency);
                    i.lstSpecializations = new SelectList(data.Specializations, "id", "description", i.specialization);
                }

                return View(item);
            }
            else
            {
                return CustomMessage(res.Content);
            }
        }
Пример #3
0
 public ActionResult CustomMessage(CustomException message)
 {
     return View("CustomMessage", message);
 }
        public ActionResult Education(List<EducationViewModel> item, IEnumerable<long> remove_educ)
        {
            try
            {
                List<EducationViewModel> modelAdd = new List<EducationViewModel>();
                List<EducationViewModel> modelUpdate = new List<EducationViewModel>();

                int index = 0;
                foreach (var model in item)
                {
                    if (model.field_study > 0)
                    {
                        ModelState.Remove("[" + index + "].other_field_study");
                    }

                    if (model.field_study == 0)
                    {
                        ModelState["[" + index + "].field_study"].Errors.Clear();
                    }

                    ModelState.Remove("[" + index + "]");

                    index++;

                    // CHECK IF UPDATE OR ADD
                    if (model.educid == 0)
                    {
                        modelAdd.Add(model);
                    }
                    else
                    {
                        modelUpdate.Add(model);
                    }
                }

                if (ModelState.IsValid)
                {
                    EducationCollectionViewModel model = new EducationCollectionViewModel();
                    model.add = modelAdd;
                    model.update = modelUpdate;
                    model.remove = remove_educ;
                    model.applicant = UserHelpers.GetUser();

                    SetRequestURL(APIURL.APPLICANT_UPDATE_EDUCATION, Method.POST);
                    request.AddBody(model);

                    var response = rest.Execute(request);

                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        Applicant user = JsonConvert.DeserializeObject<Applicant>(response.Content);

                        Session["MESSAGE"] = new CustomException(Success.EDUCATION_UPDATE, MESSAGE_TYPE.SUCCESS);
                        if (user.registration_step != Constants.REG_STEP_LAND || user.registration_step != Constants.REG_STEP_SEA)
                        {
                            return RedirectToAction("LandBased");
                        }
                        else
                        {
                            return RedirectToAction("EducationInfo");
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", JsonConvert.DeserializeObject<CustomException>(response.Content).Message);
                    }
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex);
            }

            SetRequestURL(APIURL.EDUCATION_METADATA, Method.GET);
            request.AddParameter("id", UserHelpers.GetUser().id);
            var res = rest.Execute(request);

            if (res.StatusCode == HttpStatusCode.OK)
            {
                EducationMetadata data = JsonConvert.DeserializeObject<EducationMetadata>(res.Content);
                #region label
                if (data.count == 0)
                {
                    ViewBag.EducationLabel = "Highest Educational Level";
                }
                else
                {
                    ViewBag.EducationLabel = "Education";
                }

                ViewBag.ActiveEducation = "active";
                #endregion

                foreach (var i in item)
                {
                    i.lstFields = new SelectList(data.fields, "id", "description", i.field_study);
                    i.lstLevels = new SelectList(data.levels, "id", "description", i.level);
                }

                return View(item);
            }
            else
            {
                return CustomMessage(res.Content);
            }
        }
Пример #5
0
 public void SetMessage(string message, MESSAGE_TYPE type)
 {
     Session["MESSAGE"] = new CustomException(message, type);
 }