/// <summary>
        ///
        /// </summary>
        /// <param name="model"></param>
        public static void Update(FluctuationInsuranceModel model)
        {
            // int entity
            var entity = new hr_FluctuationInsurance();

            // fill entity
            model.FillEntity(ref entity);

            hr_FluctuationInsuranceServices.Update(entity);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="model"></param>
        public static FluctuationInsuranceModel Create(FluctuationInsuranceModel model)
        {
            // init entity
            var entity = new hr_FluctuationInsurance();

            // fill entity
            model.FillEntity(ref entity);

            // create
            return(new FluctuationInsuranceModel(hr_FluctuationInsuranceServices.Create(entity)));
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="model"></param>
        private void ProcessInsurance(SalaryDecisionModel model)
        {
            var insuranceModel = new FluctuationInsuranceModel()
            {
                RecordId      = model.RecordId,
                ReasonId      = !string.IsNullOrEmpty(hdfReason.Text) ? Convert.ToInt32(hdfReason.Text) : 0,
                EffectiveDate = model.EffectiveDate,
                CreatedBy     = CurrentUser.User.UserName,
                CreatedDate   = DateTime.Now,
                EditedBy      = "",
                EditedDate    = DateTime.Now
            };

            if (!string.IsNullOrEmpty(hdfInsuranceType.Text))
            {
                insuranceModel.Type = (InsuranceType)Enum.Parse(typeof(InsuranceType), hdfInsuranceType.Text);
            }

            //check exist insurance
            var checkModel = FluctuationInsuranceController.GetByRecordId(model.RecordId, insuranceModel.EffectiveDate.Month, insuranceModel.EffectiveDate.Year);

            if (checkModel != null)
            {
                //update
                insuranceModel.Id         = checkModel.Id;
                insuranceModel.EditedBy   = CurrentUser.User.UserName;
                insuranceModel.EditedDate = DateTime.Now;

                //update
                FluctuationInsuranceController.Update(insuranceModel);
            }
            else
            {
                //create
                FluctuationInsuranceController.Create(insuranceModel);
            }
        }
Beispiel #4
0
        /// <summary>
        /// insert or update
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void InsertOrUpdate(object sender, DirectEventArgs e)
        {
            try
            {
                // init entity
                var model = new DecisionModel();

                // check id
                if (!string.IsNullOrEmpty(hdfId.Text) && Convert.ToInt32(hdfId.Text) > 0)
                {
                    var result = DecisionController.GetById(Convert.ToInt32(hdfId.Text));;
                    if (result != null)
                    {
                        model = result;
                    }
                }

                // set new props for entity
                model.Name = txtName.Text;
                if (!string.IsNullOrEmpty(hdfType.Text))
                {
                    model.Type = (DecisionType)Enum.Parse(typeof(DecisionType), hdfType.Text);
                }
                var util = new ConvertUtils();
                if (!util.IsDateNull(dfDecisionDate.SelectedDate))
                {
                    model.DecisionDate = dfDecisionDate.SelectedDate;
                }
                if (!string.IsNullOrEmpty(hdfReason.Text))
                {
                    model.ReasonId = Convert.ToInt32(hdfReason.Text);
                }
                if (!string.IsNullOrEmpty(hdfChooseEmployee.Text))
                {
                    model.RecordId = Convert.ToInt32(hdfChooseEmployee.Text);
                }
                // check entity id
                if (model.Id > 0)
                {
                    model.EditedDate = DateTime.Now;
                    model.EditedBy   = CurrentUser.User.UserName;
                    // update
                    DecisionController.Update(model);
                }
                else
                {
                    model.CreatedBy   = CurrentUser.User.UserName;
                    model.CreatedDate = DateTime.Now;
                    model.EditedDate  = DateTime.Now;
                    model.EditedBy    = "";

                    // insert
                    DecisionController.Create(model);

                    //create decrease insurance
                    if (!string.IsNullOrEmpty(hdfType.Text) &&
                        (hdfType.Text == ((int)DecisionType.Leave).ToString() ||
                         hdfType.Text == ((int)DecisionType.Maternity).ToString()))
                    {
                        var insuranceModel = new FluctuationInsuranceModel()
                        {
                            RecordId      = model.RecordId,
                            Type          = InsuranceType.Decrease,
                            EffectiveDate = model.DecisionDate,
                            ReasonId      = model.ReasonId,
                            CreatedBy     = CurrentUser.User.UserName,
                            CreatedDate   = DateTime.Now,
                            EditedDate    = DateTime.Now,
                            EditedBy      = ""
                        };

                        //create
                        FluctuationInsuranceController.Create(insuranceModel);
                    }
                }


                // hide window
                wdSetting.Hide();

                //reset form
                ResetForm();
                // reload data
                gpDecision.Reload();
            }
            catch (Exception exception)
            {
                Dialog.ShowError(exception);
            }
        }