Example #1
0
        private bool CheckExists(H_Model model, HMSEntities db)
        {
            H_Model obj = null;

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

            result.IsSuccess = true;
            using (var db = new HMSEntities(connectString))
            {
                if (!CheckExists(model, db))
                {
                    if (model.Id == 0)
                    {
                        db.H_Model.Add(model);
                    }
                    else
                    {
                        var found = db.H_Model.FirstOrDefault(x => !x.IsDeleted && x.Id == model.Id);
                        if (found != null)
                        {
                            found.Code = model.Code;
                            found.Note = model.Note;
                        }
                        else
                        {
                            result.IsSuccess = false;
                            result.sms       = "Model xe đã 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);
            }
        }
        public JsonResult Save(H_Model model)
        {
            var rs = BLLModel.Instance.InsertOrUpdate(App_Global.AppGlobal.Connectionstring, model);

            return(Json(rs));
        }