protected bool ValidateAdditionalMissionOrderEditModel(AdditionalMissionOrderEditModel model)
 {
     //return false;
     /*if (RequestBl.CheckOtherOrdersExists(model))
         ModelState.AddModelError("BeginMissionDate", StrOtherOrdersExists);*/
     return ModelState.IsValid;
 }
        public ActionResult AdditionalMissionOrderEdit(AdditionalMissionOrderEditModel model)
        {
            CorrectCheckboxes(model);
            //CorrectDropdowns(model);
            if (!ValidateAdditionalMissionOrderEditModel(model))
            {
                //model.IsApproved = false;
                //model.IsApprovedForAll = false;
                //RequestBl.ReloadDictionaries(model);
                return View(model);
            }

            string error;
            if (!RequestBl.SaveAdditionalMissionOrderEditModel(model, out error))
            {
                if (model.ReloadPage)
                {
                    ModelState.Clear();
                    if (!string.IsNullOrEmpty(error))
                        ModelState.AddModelError("", error);
                    return View(RequestBl.GetAdditionalMissionOrderEditModel(model.Id));
                }
                if (!string.IsNullOrEmpty(error))
                    ModelState.AddModelError("", error);
            }
            if (!string.IsNullOrEmpty(error))
                return View(model);
            return RedirectToAction("Index");
        }
        protected void CorrectCheckboxes(AdditionalMissionOrderEditModel model)
        {
            if (!model.IsChiefApproveAvailable /*&& model.IsChiefApprovedHidden.Value*/)
            {
                if (ModelState.ContainsKey("IsChiefApproved"))
                    ModelState.Remove("IsChiefApproved");
                model.IsChiefApproved = model.IsChiefApprovedHidden;
            }
            if (!model.IsManagerApproveAvailable /*&& model.IsManagerApprovedHidden.Value*/)
            {
                if (ModelState.ContainsKey("IsManagerApproved"))
                    ModelState.Remove("IsManagerApproved");
                model.IsManagerApproved = model.IsManagerApprovedHidden;
            }
            if (!model.IsUserApprovedAvailable && model.IsUserApprovedHidden)
            {
                if (ModelState.ContainsKey("IsUserApproved"))
                    ModelState.Remove("IsUserApproved");
                model.IsUserApproved = model.IsUserApprovedHidden;
            }
            if (ModelState.ContainsKey("IsChiefApproveNeed"))
                ModelState.Remove("IsChiefApproveNeed");
            model.IsChiefApproveNeed = model.IsChiefApproveNeedHidden;

            if (model.IsManagerApproveAvailable && model.IsManagerApproved.HasValue
                && !model.IsManagerApproved.Value)
            {
                if (ModelState.ContainsKey("IsManagerApproved"))
                    ModelState.Remove("IsManagerApproved");
            }
            if (model.IsChiefApproveAvailable && model.IsChiefApproved.HasValue
                && !model.IsChiefApproved.Value)
            {
                if (ModelState.ContainsKey("IsChiefApproved"))
                    ModelState.Remove("IsChiefApproved");
                if (ModelState.ContainsKey("IsManagerApproved"))
                    ModelState.Remove("IsManagerApproved");
            }
            //if (!model.IsEditable)
            //{
            //    if (model.IsResidencePaidHidden)
            //    {
            //        if (ModelState.ContainsKey("IsResidencePaid"))
            //            ModelState.Remove("IsResidencePaid");
            //        model.IsResidencePaid = model.IsResidencePaidHidden;
            //    }
            //    if (model.IsAirTicketsPaidHidden)
            //    {
            //        if (ModelState.ContainsKey("IsAirTicketsPaid"))
            //            ModelState.Remove("IsAirTicketsPaid");
            //        model.IsAirTicketsPaid = model.IsAirTicketsPaidHidden;
            //    }
            //    if (model.IsTrainTicketsPaidHidden)
            //    {
            //        if (ModelState.ContainsKey("IsTrainTicketsPaid"))
            //            ModelState.Remove("IsTrainTicketsPaid");
            //        model.IsTrainTicketsPaid = model.IsTrainTicketsPaidHidden;
            //    }
            //}
        }