public ResponseModel InsertOrUpdate(string connectString, H_NgheNghiep NhapPT)
        {
            var result = new ResponseModel();

            result.IsSuccess = true;
            using (var db = new HMSEntities(connectString))
            {
                if (NhapPT.Id == 0)
                {
                    db.H_NgheNghiep.Add(NhapPT);
                }
                else
                {
                    var found = db.H_NgheNghiep.FirstOrDefault(x => !x.IsDeleted && x.Id == NhapPT.Id);
                    if (found != null)
                    {
                        found.Code = NhapPT.Code;
                        found.Note = NhapPT.Note;
                    }
                    else
                    {
                        result.IsSuccess = false;
                        result.sms       = "Nghề nghiệp này đã bị xóa hoặc không tồn tại trong hệ thống.!";
                    }
                }
                if (result.IsSuccess)
                {
                    db.SaveChanges();
                }
                return(result);
            }
        }
예제 #2
0
        private bool CheckExists(H_NgheNghiep Job, HMSEntities db)
        {
            H_NgheNghiep obj = null;

            if (!string.IsNullOrEmpty(Job.Code))
            {
                obj = db.H_NgheNghiep.FirstOrDefault(x => !x.IsDeleted && x.Id != Job.Id && x.Code.Trim().ToUpper().Equals(Job.Code.Trim().ToUpper()));
            }
            return(obj != null ? true : false);
        }
예제 #3
0
        public ResponseModel InsertOrUpdate(string connectString, H_NgheNghiep Job)
        {
            var result = new ResponseModel();

            result.IsSuccess = true;
            using (var db = new HMSEntities(connectString))
            {
                if (!CheckExists(Job, db))
                {
                    if (Job.Id == 0)
                    {
                        db.H_NgheNghiep.Add(Job);
                    }
                    else
                    {
                        var found = db.H_NgheNghiep.FirstOrDefault(x => !x.IsDeleted && x.Id == Job.Id);
                        if (found != null)
                        {
                            found.Code = Job.Code;
                            found.Note = Job.Note;
                        }
                        else
                        {
                            result.IsSuccess = false;
                            result.sms       = "Nghề nghiệp này đã bị xóa hoặc không tồn tại trong hệ thống.!";
                        }
                    }
                    if (result.IsSuccess)
                    {
                        db.SaveChanges();
                    }
                }
                else
                {
                    result.IsSuccess = false;
                    result.sms       = "Mã này đã tồn tại trong hệ thống. Vui lòng chọn lại mã khác.";
                }
                return(result);
            }
        }