Example #1
0
        public Result<bool> edit_phieumuontra(phieumuontra_ett phieumuontra, List<string> list_masach)
        {
            Result<bool> rs = new Result<bool>();
            try
            {
                // find the only row to edit
                var dt = db.tbl_phieumuon_tras.Where(o => o.sophieumuon == phieumuontra.sophieumuon).SingleOrDefault();
                // if fields are null or "" then maintaining the old data;
                if (phieumuontra.madg != null)
                {
                    dt.madg = phieumuontra.madg;
                }
                if (phieumuontra.manv != null)
                {
                    dt.manv = phieumuontra.manv;
                }
                if (phieumuontra.ngaymuon != null && phieumuontra.ngaymuon != "")
                {
                    dt.ngaymuon = phieumuontra.ngaymuon;
                }
                if (phieumuontra.ngaytra != null && phieumuontra.ngaytra != "")
                {
                    dt.ngaytra = phieumuontra.ngaytra;
                }
                if (phieumuontra.ghichu != null && phieumuontra.ghichu != "")
                {
                    dt.ghichu = phieumuontra.ghichu;
                }
                if (phieumuontra.xacnhantra != null)
                {
                    dt.xacnhantra = phieumuontra.xacnhantra;
                    if (phieumuontra.xacnhantra==true)
                    {
                        if (list_masach.Count() > 0)
                        {
                            foreach (string item in list_masach)
                            {
                                var data = db.tbl_saches.Where(o => o.masach == int.Parse(item)).SingleOrDefault();
                                data.soluong++;
                            }
                        }
                    }
                }

                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;
            }
        }
Example #2
0
        public Result<phieumuontra_ett> insert_phieumuontra(phieumuontra_ett phieumuontra, List<string> list_masach)
        {
            Result<phieumuontra_ett> rs = new Result<phieumuontra_ett>();

            try
            {
                // create new tbl_phieumuontra to insert to database_context
                tbl_phieumuon_tra temp = new tbl_phieumuon_tra();
                temp.manv = phieumuontra.manv;
                temp.madg = phieumuontra.madg;
                temp.ngaytra = phieumuontra.ngaytra;
                temp.ngaymuon = phieumuontra.ngaymuon;
                temp.xacnhantra = phieumuontra.xacnhantra;
                temp.ghichu = phieumuontra.ghichu;

                db.tbl_phieumuon_tras.InsertOnSubmit(temp);

                if (list_masach.Count() > 0)
                {
                    foreach (string item in list_masach)
                    {
                        var dt = db.tbl_saches.Where(o => o.masach == int.Parse(item)).SingleOrDefault();
                        dt.soluong--;
                    }
                }

                db.SubmitChanges();

                var last_record = db.tbl_phieumuon_tras.OrderByDescending(o => o.sophieumuon).Take(1);
                if (last_record.Count() > 0)
                {
                    foreach (var item in last_record)
                    {
                        phieumuontra_ett temp1 = new phieumuontra_ett(item);
                        rs.data = temp1;
                    }
                }
                rs.errcode = ErrorCode.sucess;
                return rs;
            }
            catch (Exception e)
            {
                rs.data = null;
                rs.errcode = ErrorCode.fail;
                rs.errInfor = e.ToString();
                return rs;
            }
        }