Beispiel #1
0
        public Result <List <sach_ett> > select_all_sach()
        {
            Result <List <sach_ett> > rs = new Result <List <sach_ett> >();

            try
            {
                List <sach_ett> lst = new List <sach_ett>();
                var             dt  = db.tbl_saches;
                if (dt.Count() > 0)
                {
                    foreach (tbl_sach item in dt)
                    {
                        sach_ett temp = new sach_ett(item);
                        lst.Add(temp);
                    }
                    rs.data    = lst;
                    rs.errcode = ErrorCode.sucess;
                }
                else
                {
                    rs.data     = null;
                    rs.errInfor = Constants.empty_data;
                }
                return(rs);
            }
            catch (Exception e)
            {
                rs.data     = null;
                rs.errInfor = e.ToString();
                rs.errcode  = ErrorCode.fail;
                return(rs);
            }
        }
Beispiel #2
0
        public Result <bool> insert_sach(sach_ett sach)
        {
            Result <bool> rs = new Result <bool>();

            try
            {
                // create new tbl_sach to insert to database_context
                tbl_sach temp = new tbl_sach();
                temp.tensach  = sach.tensach;
                temp.matg     = sach.matg;
                temp.manxb    = sach.manxb;
                temp.malv     = sach.malv;
                temp.sotrang  = sach.sotrang;
                temp.soluong  = sach.soluong;
                temp.ngaynhap = sach.ngaynhap;

                db.tbl_saches.InsertOnSubmit(temp);
                db.SubmitChanges();

                rs.data    = true;
                rs.errcode = ErrorCode.sucess;
                return(rs);
            }
            catch (Exception e)
            {
                rs.data     = false;
                rs.errcode  = ErrorCode.fail;
                rs.errInfor = e.ToString();
                return(rs);
            }
        }
Beispiel #3
0
        public Result <bool> edit_sach(sach_ett sach)
        {
            Result <bool> rs = new Result <bool>();

            try
            {
                // find the only row to edit
                var dt = db.tbl_saches.Where(o => o.masach == sach.masach).SingleOrDefault();
                // if fields are null or "" then maintaining the old data;
                if (sach.tensach != null && sach.tensach != "")
                {
                    dt.tensach = sach.tensach;
                }
                if (sach.matg != null)
                {
                    dt.matg = sach.matg;
                }
                if (sach.manxb != null)
                {
                    dt.manxb = sach.manxb;
                }
                if (sach.malv != null)
                {
                    dt.malv = sach.malv;
                }
                if (sach.soluong != null)
                {
                    dt.soluong = sach.soluong;
                }
                if (sach.sotrang != null)
                {
                    dt.sotrang = sach.sotrang;
                }
                if (sach.ngaynhap != null || sach.ngaynhap != "")
                {
                    dt.ngaynhap = sach.ngaynhap;
                }

                db.SubmitChanges();
                rs.data    = true;
                rs.errcode = ErrorCode.sucess;
                return(rs);
            }
            catch (Exception e)
            {
                rs.data     = false;
                rs.errcode  = ErrorCode.fail;
                rs.errInfor = e.ToString();
                return(rs);
            }
        }