public void Check(SalaryItem record, SalaryItemFormViewModel model)
 {
     if (model.ItemType != 2)
     {
         record.Multiple = false;
     }
     if (model.ValueType == 1)
     {
         record.MinValue     = null;
         record.MaxValue     = null;
         record.InValidValue = null;
     }
     else if (model.ValueType == 2)
     {
         record.MinValue     = null;
         record.MaxValue     = null;
         record.InValidValue = null;
         record.FormulaId    = null;
     }
     if (model.UoMeasure != 1 && model.IsSalaryItem == false)
     {
         record.InputCurr = null;
     }
     if (model.IsSalaryItem == true)
     {
         record.UoMeasure = 1;
     }
     if (model.IsSalaryItem == false)
     {
         record.ItemType = 2;
     }
 }
        public ActionResult Details(SalaryItemFormViewModel model, OptionsViewModel moreInfo)
        {
            List <Error> errors = new List <Error>();

            if (ModelState.IsValid)
            {
                if (ServerValidationEnabled)
                {
                    errors = _hrUnitOfWork.SiteRepository.CheckForm(new CheckParm
                    {
                        CompanyId    = CompanyId,
                        ObjectName   = "SalaryItems",
                        TableName    = "SalaryItems",
                        ParentColumn = "CompanyId",
                        Columns      = Models.Utils.GetColumnViews(ModelState.Where(a => !a.Key.Contains('.'))),
                        Culture      = Language
                    });

                    if (errors.Count() > 0)
                    {
                        foreach (var e in errors)
                        {
                            foreach (var errorMsg in e.errors)
                            {
                                ModelState.AddModelError(errorMsg.field, errorMsg.message);
                            }
                        }

                        return(Json(Models.Utils.ParseFormErrors(ModelState)));
                    }
                }

                SalaryItem record;

                //insert
                if (model.Id == 0)
                {
                    record = new SalaryItem();
                    AutoMapper(new Models.AutoMapperParm
                    {
                        Destination = record,
                        Source      = model,
                        ObjectName  = "SalaryItems",
                        Options     = moreInfo,
                        Transtype   = TransType.Insert
                    });
                    record.CreatedUser = UserName;
                    record.CreatedTime = DateTime.Now;
                    record.CompanyId   = model.IsLocal ? CompanyId : (int?)null;
                    Check(record, model);
                    _hrUnitOfWork.PayrollRepository.Add(record);
                }
                //update
                else
                {
                    record = _hrUnitOfWork.Repository <SalaryItem>().FirstOrDefault(a => a.Id == model.Id);
                    AutoMapper(new Models.AutoMapperParm
                    {
                        Destination = record,
                        Source      = model,
                        ObjectName  = "SalaryItems",
                        Options     = moreInfo,
                        Transtype   = TransType.Update
                    });
                    record.ModifiedTime = DateTime.Now;
                    record.ModifiedUser = UserName;
                    record.CompanyId    = model.IsLocal ? CompanyId : (int?)null;
                    Check(record, model);
                    _hrUnitOfWork.PayrollRepository.Attach(record);
                    _hrUnitOfWork.PayrollRepository.Entry(record).State = EntityState.Modified;
                }

                if (errors.Count > 0)
                {
                    return(Json(errors.First().errors.First().message));
                }

                errors = SaveChanges(Language);

                var message = "OK";
                if (errors.Count > 0)
                {
                    message = errors.First().errors.First().message;
                }

                return(Json(message));
            }

            return(Json(Models.Utils.ParseFormErrors(ModelState)));
        }