/// <summary>
        /// Add and Edit Document
        /// </summary>
        /// <param name="data"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public CommonResponse AddAndEditCheckListJobAssignedResource(CheckListJobAssignedResourceMasterCustom data, long userId = 0)
        {
            CommonResponse obj = new CommonResponse();

            try
            {
                var res = db.CheckListJobAssignedResourceMaster.Where(m => m.CheckListJobMasterId == data.checkListJobMasterId && m.CheckListJobGroupId == data.checkListJobGroupId).FirstOrDefault();
                if (res == null)
                {
                    try
                    {
                        CheckListJobAssignedResourceMaster item = new CheckListJobAssignedResourceMaster();
                        item.CheckListJobMasterId       = data.checkListJobMasterId;
                        item.CheckListJobGroupId        = data.checkListJobGroupId;
                        item.PrimaryResource            = data.primaryResource;
                        item.PrimaryResourceToAllFlag   = data.primaryResourceToAllFlag;
                        item.SecondaryResource          = data.secondaryResource;
                        item.SecondaryResourceToAllFlag = data.secondaryResourceToAllFlag;
                        item.IsActive  = true;
                        item.IsDeleted = false;
                        item.CreatedBy = userId;
                        item.CreatedOn = DateTime.Now;
                        db.CheckListJobAssignedResourceMaster.Add(item);
                        db.SaveChanges();
                        obj.response = ResourceResponse.AddedSucessfully;
                        obj.isStatus = true;
                    }
                    catch (Exception ex)
                    {
                        log.Error(ex); if (ex.InnerException != null)
                        {
                            log.Error(ex.InnerException.ToString());
                        }
                        obj.response = ResourceResponse.ExceptionMessage;
                        obj.isStatus = false;
                    }
                }
                else
                {
                    try
                    {
                        res.CheckListJobMasterId       = data.checkListJobMasterId;
                        res.CheckListJobGroupId        = data.checkListJobGroupId;
                        res.PrimaryResource            = data.primaryResource;
                        res.PrimaryResourceToAllFlag   = data.primaryResourceToAllFlag;
                        res.SecondaryResource          = data.secondaryResource;
                        res.SecondaryResourceToAllFlag = data.secondaryResourceToAllFlag;
                        res.ModifiedBy = userId;
                        res.ModifiedOn = DateTime.Now;
                        db.SaveChanges();
                        obj.response = ResourceResponse.UpdatedSucessfully;
                        obj.isStatus = true;
                    }
                    catch (Exception ex)
                    {
                        log.Error(ex); if (ex.InnerException != null)
                        {
                            log.Error(ex.InnerException.ToString());
                        }
                        obj.response = ResourceResponse.ExceptionMessage;
                        obj.isStatus = false;
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(ex); if (ex.InnerException != null)
                {
                    log.Error(ex.InnerException.ToString());
                }
                obj.response = ResourceResponse.ExceptionMessage;
                obj.isStatus = false;
            }
            return(obj);
        }
        /// <summary>
        /// Add And Edit Check List Job Assigned Resource All
        /// </summary>
        /// <param name="checkListJobMasterId"></param>
        /// <param name="checkListJobGroupId"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public CommonResponse AddAndEditCheckListJobAssignedResourceAll(int checkListJobMasterId, long userId = 0)
        {
            CommonResponse obj            = new CommonResponse();
            CommonFunction commonFunction = new CommonFunction();

            try
            {
                var job = db.CheckListJobMaster.Where(m => m.CheckListJobId == checkListJobMasterId).FirstOrDefault();

                List <int> gppids = job.CheckListGroup.Split(',').Select(int.Parse).ToList();
                foreach (var grp in gppids)
                {
                    int checkListJobGroupId = grp;



                    var res = db.CheckListJobAssignedResourceMaster.Where(m => m.CheckListJobMasterId == checkListJobMasterId && m.CheckListJobGroupId == checkListJobGroupId).FirstOrDefault();

                    var result = String.Join(",", db.UserDetails.Where(wf => wf.IsDeleted == false && wf.RoleId == 3).Select(wf => wf.UserId).ToList());

                    if (res == null)
                    {
                        try
                        {
                            CheckListJobAssignedResourceMaster item = new CheckListJobAssignedResourceMaster();
                            item.CheckListJobMasterId     = checkListJobMasterId;
                            item.CheckListJobGroupId      = checkListJobGroupId;
                            item.PrimaryResource          = result;
                            item.PrimaryResourceToAllFlag = true;
                            item.IsActive  = true;
                            item.IsDeleted = false;
                            item.CreatedBy = userId;
                            item.CreatedOn = DateTime.Now;
                            db.CheckListJobAssignedResourceMaster.Add(item);
                            db.SaveChanges();
                            obj.response = ResourceResponse.AddedSucessfully;
                            obj.isStatus = true;
                        }
                        catch (Exception ex)
                        {
                            log.Error(ex); if (ex.InnerException != null)
                            {
                                log.Error(ex.InnerException.ToString());
                            }
                            obj.response = ResourceResponse.ExceptionMessage;
                            obj.isStatus = false;
                        }
                    }
                    else
                    {
                        try
                        {
                            if (res.PrimaryResource == null || res.PrimaryResource.Length == 0)
                            {
                                res.CheckListJobMasterId     = checkListJobMasterId;
                                res.CheckListJobGroupId      = checkListJobGroupId;
                                res.PrimaryResource          = result;
                                res.PrimaryResourceToAllFlag = true;
                                res.ModifiedBy = userId;
                                res.ModifiedOn = DateTime.Now;
                                db.SaveChanges();
                                obj.response = ResourceResponse.UpdatedSucessfully;
                                obj.isStatus = true;
                            }
                        }
                        catch (Exception ex)
                        {
                            log.Error(ex); if (ex.InnerException != null)
                            {
                                log.Error(ex.InnerException.ToString());
                            }
                            obj.response = ResourceResponse.ExceptionMessage;
                            obj.isStatus = false;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(ex); if (ex.InnerException != null)
                {
                    log.Error(ex.InnerException.ToString());
                }
                obj.response = ResourceResponse.ExceptionMessage;
                obj.isStatus = false;
            }
            return(obj);
        }