Ejemplo n.º 1
0
        private AjaxReponseModel <dynamic> UpdateCustomer()
        {
            var response = new AjaxReponseModel <dynamic>(AjaxReponseStatusEnum.Success);

            try
            {
                var data = new StreamReader(Request.InputStream).ReadToEnd();
                var dym  = JsonConvert.DeserializeObject <Customer>(data);
                int maKH = dym.MaKH;
                using (var db = new qlksEntities())
                {
                    tblKhachHang kh = db.tblKhachHangs.SingleOrDefault(w => w.MaKH == maKH);
                    kh.TenKH    = String.IsNullOrEmpty(dym.TenKH.ToString()) ? String.Empty : dym.TenKH.ToString().Trim();
                    kh.SDT      = String.IsNullOrEmpty(dym.SDT.ToString()) ? String.Empty : dym.SDT.ToString().Trim();
                    kh.Email    = String.IsNullOrEmpty(dym.Email.ToString()) ? String.Empty : dym.Email.ToString().Trim();
                    kh.DiaChi   = String.IsNullOrEmpty(dym.DiaChi.ToString()) ? String.Empty : dym.DiaChi.ToString().Trim();
                    kh.NgaySinh = dym.NgaySinh;
                    kh.GioiTinh = dym.GioiTinh;
                    kh.CMND     = dym.CMND;

                    db.SaveChanges();
                    response.Message = "SUCCESS";
                };

                return(response);
            }
            catch (Exception e)
            {
                response.Message = "ERROR";
                return(response);
            }
            finally
            {
            }
        }
Ejemplo n.º 2
0
        private AjaxReponseModel <dynamic> DeleteCustomer()
        {
            var response = new AjaxReponseModel <dynamic>(AjaxReponseStatusEnum.Success);

            try
            {
                var data = new StreamReader(Request.InputStream).ReadToEnd();
                var dym  = JsonConvert.DeserializeObject <Customer>(data);
                int maKH = dym.MaKH;
                using (var db = new qlksEntities())
                {
                    tblKhachHang     kh  = db.tblKhachHangs.SingleOrDefault(w => w.MaKH == maKH);
                    tblPhieuDatPhong pdp = db.tblPhieuDatPhongs.SingleOrDefault(w => w.MaKH == maKH);
                    if (pdp != null && pdp.MaPhieuDP > 0)
                    {
                        response.Message = "PDP_EXIST";
                    }
                    else
                    {
                        db.tblKhachHangs.Remove(kh);
                        db.SaveChanges();
                        response.Message = "SUCCESS";
                    }
                };

                return(response);
            }
            catch (Exception e)
            {
                response.Message = "ERROR";
                return(response);
            }
            finally
            {
            }
        }