コード例 #1
0
 public Status DeleteBill(int id)
 {
     this._logger.LogWarning("The server execute DeleteBill Fuction  --" + DateTime.Now.ToString());
     using (SchoolCookHouseContext dbcontext = new SchoolCookHouseContext())
     {
         TBill userInfo = new TBill()
         {
             Id = id
         };
         try
         {
             var a = dbcontext.TBill.Where(a => true).ToList().Find(a => a.Id == id);
             dbcontext.TBill.Remove(a);
             dbcontext.SaveChanges();
             Status status = new Status()
             {
                 StatusCode = 200,
                 Message    = "删除成功",
                 ReturnTime = DateTime.Now
             };
             return(status);
         }
         catch (Exception ex)
         {
             this._logger.LogWarning("The server execute DeleteBill Fuction  --" + ex.Message + DateTime.Now.ToString());
             Status status = new Status()
             {
                 StatusCode = 0,
                 Message    = "删除失败",
                 ReturnTime = DateTime.Now
             };
             return(status);
         }
     }
 }
コード例 #2
0
        public Status UpdateBill(int id, float price, DateTime BillDatetime, string conductor, string remark)
        {
            this._logger.LogWarning("The server execute UpdateBill Fuction  --" + DateTime.Now.ToString());
            using (SchoolCookHouseContext dbcontext = new SchoolCookHouseContext())
            {
                TBill bill = new TBill()
                {
                    Price        = price,
                    BillDatetime = BillDatetime,
                    Conductor    = conductor,
                    Remark       = remark,
                };

                var ReadPeoples = dbcontext.TBill.Where(a => true).ToList().Find(a => a.Id == id);

                ReadPeoples.Price        = bill.Price;
                ReadPeoples.BillDatetime = bill.BillDatetime;
                ReadPeoples.Conductor    = bill.Conductor;
                ReadPeoples.Remark       = bill.Remark;

                try
                {
                    dbcontext.Entry(ReadPeoples).State = EntityState.Modified;
                    dbcontext.SaveChanges();
                    Status status = new Status()
                    {
                        StatusCode = 200,
                        Message    = "修改成功",
                        ReturnTime = DateTime.Now
                    };
                    return(status);
                }
                catch (Exception ex)
                {
                    this._logger.LogWarning("The server execute UpdateBill Fuction  --" + ex.Message + DateTime.Now.ToString());
                    Status status = new Status()
                    {
                        StatusCode = 0,
                        Message    = "修改失败",
                        ReturnTime = DateTime.Now
                    };
                    return(status);
                }
            }
        }
コード例 #3
0
 public Status AddBill(float price, DateTime BillDatetime, string conductor, string remark)
 {
     this._logger.LogWarning("The server execute AddBill Fuction  --" + DateTime.Now.ToString());
     using (SchoolCookHouseContext dbcontext = new SchoolCookHouseContext())
     {
         TBill bill = new TBill()
         {
             Price        = price,
             BillDatetime = BillDatetime,
             Conductor    = conductor,
             Remark       = remark,
         };
         try
         {
             dbcontext.Add(bill);
             dbcontext.SaveChanges();
             Status status = new Status()
             {
                 StatusCode = 200,
                 Message    = "添加成功",
                 ReturnTime = DateTime.Now
             };
             return(status);
         }
         catch (Exception ex)
         {
             this._logger.LogWarning("The server execute AddBill Fuction  --" + ex.Message + DateTime.Now.ToString());
             Status status = new Status()
             {
                 StatusCode = 0,
                 Message    = "添加失败",
                 ReturnTime = DateTime.Now
             };
             return(status);
         }
     }
 }