예제 #1
0
        public JsonResult SaveData(string model)
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            LoaiPhong            loaiPhong  = serializer.Deserialize <LoaiPhong>(model);
            bool   status  = false;
            string message = string.Empty;

            if (loaiPhong.ID == 0)
            {
                try
                {
                    _loaiPhongRepository.Add(loaiPhong);
                    _unitOfWork.Commit();
                    status = true;
                }
                catch (Exception ex)
                {
                    status  = false;
                    message = ex.Message;
                }
            }
            else
            {
                var entity = _loaiPhongRepository.GetSingleById(loaiPhong.ID);
                try
                {
                    entity.TenLoaiPhong = loaiPhong.TenLoaiPhong;
                    _loaiPhongRepository.Update(entity);
                    _unitOfWork.Commit();
                    status = true;
                }
                catch (Exception ex)
                {
                    status  = false;
                    message = ex.Message;
                }
            }
            return(Json(new
            {
                status = status,
                message = message
            }));
        }