// DELETE api/<controller>
 public void Delete(Guid ID)
 {
     var service = new Sal_UnusualAllowanceServices();
     var result  = service.Remove <Sal_UnusualAllowanceEntity>(ID);
 }
        public Sal_UnusualAllowanceModel Post([Bind] Sal_UnusualAllowanceModel model)
        {
            #region Validate
            string        message       = string.Empty;
            string        status        = string.Empty;
            ActionService service       = new ActionService(UserLogin);
            var           checkValidate = true;
            checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData <Sal_UnusualAllowanceModel>(model, "Sal_UnusualAllowanceinfoNew", "Sal_UnusualAllowance", ref message);
            if (!checkValidate)
            {
                model.ActionStatus = message;
                return(model);
            }
            if (model != null && model.UnusualEDTypeID != null)
            {
                var entity = service.GetByIdUseStore <Cat_UnusualAllowanceCfgEntity>(model.UnusualEDTypeID.Value, ConstantSql.hrm_cat_sp_get_UnusualAllowanceCfgId, ref status);
                if (entity != null && entity.Code != null)
                {
                    if (entity.Code.Replace(" ", "") == "DEATHOFEMPLOYEE" || entity.Code.Replace(" ", "") == "HOSPITALOFEMPLOYEEMORETHANONEMONTH")
                    {
                        checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData <Sal_UnusualAllowanceModel>(model, "Sal_UnusualAllowanceinfoNew2", "Sal_UnusualAllowance", ref message);
                    }
                    else
                    {
                        checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData <Sal_UnusualAllowanceModel>(model, "Sal_UnusualAllowanceinfoNew1", "Sal_UnusualAllowance", ref message);
                    }
                    if (!checkValidate)
                    {
                        model.ActionStatus = message;
                        return(model);
                    }
                    if (entity.Code.Replace(" ", "") == "BIRTHOFACHILD" || entity.Code.Replace(" ", "") == "DEATHOFEMPLOYEECHILD" || entity.Code.Replace(" ", "") == "DEATHOFEMPLOYEESPOUSE" || entity.Code.Replace(" ", "") == "FUNERALOFPARENT")
                    {
                        checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData <Sal_UnusualAllowanceModel>(model, "Sal_UnusualAllowanceinfo1And2", "Sal_UnusualAllowance", ref message);
                        if (checkValidate == false)
                        {
                            checkValidate = true;
                            //lay thong tin cua quan he
                            var objRelativesModel      = service.GetData <Hre_RelativesModel>(Common.DotNetToOracle(model.RelativeID.ToString()), ConstantSql.hrm_hr_sp_get_RelativesById, ref status).FirstOrDefault();
                            var checkValidateRelatives = true;
                            if (objRelativesModel != null)
                            {
                                //lay all nguoi than cua nv do
                                Hre_RelativesServices hreServiveRelative = new Hre_RelativesServices();
                                var lstRelativeByProfileId = hreServiveRelative.GetRelativeByProfileId(model.ProfileID).ToList();
                                if (lstRelativeByProfileId.Count > 0)
                                {
                                    //if (model.ID == Guid.Empty)
                                    //    objRelativesModel.ID = Guid.Empty;
                                    var lstDuplicateRelativeByProfileID = lstRelativeByProfileId.
                                                                          Where(s => s.ProfileID == objRelativesModel.ProfileID && s.RelativeName == objRelativesModel.RelativeName && s.YearOfBirth == objRelativesModel.YearOfBirth).ToList();
                                    if (lstDuplicateRelativeByProfileID.Count > 0)
                                    {
                                        checkValidateRelatives = false;
                                    }
                                }
                                //  checkValidateRelatives = HRM.Business.Main.Domain.ValidatorService.OnValidateData<Hre_RelativesModel>(objRelativesModel, "Hre_Relativesinfo1And2", "Hre_Relatives", ref message);
                            }
                            if (checkValidateRelatives == false)
                            {
                                model.ActionStatus = message;
                                return(model);
                            }
                        }
                    }
                    else if (entity.Code.Replace(" ", "") == "HOSPITALOFEMPLOYEEMORETHANONEMONTH")
                    {
                        Sal_ReportService salService = new Sal_ReportService();
                        int      _daysInMonth        = System.DateTime.DaysInMonth(model.DateOccur.Value.Year, model.DateOccur.Value.Month);
                        DateTime _datestart          = new DateTime(model.DateOccur.Value.Year, model.DateOccur.Value.Month, 1);
                        DateTime _dateend            = new DateTime(model.DateOccur.Value.Year, model.DateOccur.Value.Month, _daysInMonth);
                        //List<object> paraUnusualAllowance = new List<object>();
                        //paraUnusualAllowance.AddRange(new object[7]);
                        //paraUnusualAllowance[2] = model.UnusualEDTypeID;
                        //paraUnusualAllowance[3] = _datestart;
                        //paraUnusualAllowance[4] = _dateend;
                        //paraUnusualAllowance[5] = 1;
                        //paraUnusualAllowance[6] = int.MaxValue;
                        Sal_UnusualAllowanceServices salServiceUnusualAllowance = new Sal_UnusualAllowanceServices();
                        //var lstUnusualAllowance = salServiceUnusualAllowance.GetData<Sal_UnusualAllowanceEntity>(paraUnusualAllowance, ConstantSql.hrm_sal_sp_get_UnusualAllowanceFilialWedding, ref status);
                        var lstUnusualAllowance = salServiceUnusualAllowance.GetUnusualAllowanceByUnusualEDTypeIDAndDateOccur(model.ProfileID, model.UnusualEDTypeID, _datestart, _dateend);
                        if (lstUnusualAllowance != null)
                        {
                            //lstUnusualAllowance = lstUnusualAllowance.Where(s => s.ProfileID == model.ProfileID).ToList();
                            if ((lstUnusualAllowance.Count > 0 && model.ID == Guid.Empty) || (lstUnusualAllowance.Count > 1 && model.ID != Guid.Empty))
                            {
                                checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData <Sal_UnusualAllowanceModel>(model, "Sal_UnusualAllowanceinfo3", "Sal_UnusualAllowance", ref message);
                                if (!checkValidate)
                                {
                                    model.ActionStatus = message;
                                    return(model);
                                }
                            }
                        }
                    }
                    else if (entity.Code.Replace(" ", "") == "MARRIAGEOFEMPLOYEE" || entity.Code.Replace(" ", "") == "DEATHOFEMPLOYEE")
                    {
                        checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData <Sal_UnusualAllowanceModel>(model, "Sal_UnusualAllowanceinfo5And6And7", "Sal_UnusualAllowance", ref message);
                    }
                }
            }
            if (!checkValidate)
            {
                model.ActionStatus = message;
                return(model);
            }
            #endregion

            return(service.UpdateOrCreate <Sal_UnusualAllowanceEntity, Sal_UnusualAllowanceModel>(model));
        }
Beispiel #3
0
        public Sal_UnusualAllowanceModel Post([Bind] Sal_UnusualAllowanceModel model)
        {
            var    hrService = new Hre_ProfileServices();
            var    UnusualAllowanceServices = new Sal_UnusualAllowanceServices();
            string status = string.Empty;

            #region Validate
            string message       = string.Empty;
            var    checkValidate = false;
            //kiểm tra xem có phải là đang create ở trang chi tiết nv ko
            if (model.IsGeneralProfile != null && model.IsGeneralProfile == true)
            {
                checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData <Sal_UnusualAllowanceModel>(model, "Sal_UnusualEDGeneralProfile", ref message);

                if (!checkValidate)
                {
                    model.ActionStatus = message;
                    return(model);
                }
                ActionService service = new ActionService(UserLogin);
                return(service.UpdateOrCreate <Sal_UnusualAllowanceEntity, Sal_UnusualAllowanceModel>(model));
            }
            else
            {
                if (!string.IsNullOrEmpty(model.OrgStructureIDs))
                {
                    checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData <Sal_UnusualAllowanceModel>(model, "Sal_UnusualEDOrg", ref message);
                }
                else
                {
                    checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData <Sal_UnusualAllowanceModel>(model, "Sal_UnusualED", ref message);
                }
                if (!checkValidate)
                {
                    model.ActionStatus = message;
                    return(model);
                }

                if (!string.IsNullOrEmpty(model.OrgStructureIDs))
                {
                    List <Guid> listGuid = new List <Guid>();
                    if (model.ProfileIDExclusion != null)
                    {
                        var listStr = model.ProfileIDExclusion.Split(',');

                        if (listStr[0] != "")
                        {
                            foreach (var item in listStr)
                            {
                                listGuid.Add(Guid.Parse(item));
                            }
                        }
                    }
                    List <object> listObj = new List <object>();
                    listObj.Add(model.OrgStructureID);
                    listObj.Add(string.Empty);
                    listObj.Add(string.Empty);
                    var lstProfile = hrService.GetData <Hre_ProfileIdEntity>(listObj, ConstantSql.hrm_hr_sp_get_ProfileIdsByOrgStructure, userLogin, ref status).Select(s => s.ID).ToList();
                    if (listGuid != null)
                    {
                        lstProfile = lstProfile.Where(s => !listGuid.Contains(s)).ToList();
                    }

                    List <Sal_UnusualAllowanceEntity> lstUnusualAllowance = new List <Sal_UnusualAllowanceEntity>();
                    foreach (var i in lstProfile)
                    {
                        Sal_UnusualAllowanceEntity item = new Sal_UnusualAllowanceEntity();
                        item           = model.Copy <Sal_UnusualAllowanceEntity>();
                        item.ProfileID = i;
                        lstUnusualAllowance.Add(item);
                    }
                    model.ActionStatus = UnusualAllowanceServices.Add(lstUnusualAllowance);
                    return(model);
                }
                else
                {
                    string[] listProfile = model.ProfileIDs.Split(',');
                    List <Sal_UnusualAllowanceEntity> lstUnusualAllowance = new List <Sal_UnusualAllowanceEntity>();
                    foreach (var i in listProfile)
                    {
                        Sal_UnusualAllowanceEntity item = new Sal_UnusualAllowanceEntity();
                        item           = model.Copy <Sal_UnusualAllowanceEntity>();
                        item.ProfileID = Guid.Parse(i);
                        lstUnusualAllowance.Add(item);
                    }
                    model.ActionStatus = UnusualAllowanceServices.Add(lstUnusualAllowance);
                    return(model);
                }
            }
            #endregion
        }