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

            try
            {
                var data = new StreamReader(Request.InputStream).ReadToEnd();
                var dym  = JsonConvert.DeserializeObject <Product>(data);
                int maSP = dym.MaSP;
                using (var db = new qlksEntities())
                {
                    tblSanPham sp = db.tblSanPhams.SingleOrDefault(w => w.MaSP == maSP);
                    sp.TenSP  = String.IsNullOrEmpty(dym.TenSP.ToString()) ? String.Empty : dym.TenSP.ToString().Trim();
                    sp.DonGia = dym.DonGia;

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

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

            try
            {
                var data = new StreamReader(Request.InputStream).ReadToEnd();
                var dym  = JsonConvert.DeserializeObject <Product>(data);
                int maSP = dym.MaSP;
                using (var db = new qlksEntities())
                {
                    tblSanPham      sp  = db.tblSanPhams.SingleOrDefault(w => w.MaSP == maSP);
                    tblSanPhamPhong pdp = db.tblSanPhamPhongs.SingleOrDefault(w => w.MaSP == maSP);
                    if (pdp != null && pdp.MaPhieuDP > 0)
                    {
                        response.Message = "PDP_EXIST";
                    }
                    else
                    {
                        db.tblSanPhams.Remove(sp);
                        db.SaveChanges();
                        response.Message = "SUCCESS";
                    }
                };

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