public JsonRs InsertNewOtherService(string name, int checkinID, int hotelID, int customerid, double price) { var rs = new JsonRs(); using (var db = _connectionData.OpenDbConnection()) { using (var tran = db.OpenTransaction()) { try { if ( db.Single <tbl_Product>(x => x.Name.ToUpper() == name.Trim().ToUpper()) != null) { rs.Status = "00"; rs.Message = "Dịch vụ có thể đã tồn tại trên hệ thống!"; } var p = new tbl_Product() { Status = 1, Name = name, Code = "", CreateDate = DateTime.Now, Createby = 1, DateOrder = DateTime.Now, Description = "dịch vụ khác", ModifyDate = DateTime.Now, ProductCateID = 0, ProductGroupID = 0, SalePrice = price, PriceOrder = price, SupplierID = 0, SysHotelID = hotelID, Modifyby = 1, PictureUrl = "", UnitID = 0, QuotaMinimize = 1, }; db.Save(p, true); var sv = new tbl_CustomerService() { customerid = customerid, CheckInID = checkinID, SysHotelID = hotelID, productid = p.Id, productcode = "", datecreated = DateTime.Now, Quantity = 1, status = 1, }; db.Save(sv, true); rs.Data = sv; tran.Commit(); rs.Status = "01"; return(rs); } catch (Exception e) { tran.Rollback(); rs.Status = "00"; rs.Message = "Thêm mới dịch vụ thất bại"; return(rs); throw; } } } }
public JsonRs InsertCustomeServer(int productId, int checkinID, int hotelID, int customerid, int quantity) { var rs = new JsonRs(); try { using (var db = _connectionData.OpenDbConnection()) { using (var tran = db.OpenTransaction()) { //if (db.Single<Vw_ProductService>(x => x.CheckinID == checkinID && x.productid == productId && x.status == 1) != null) //{ // rs.Status = "00"; // rs.Message = "Dịch vụ đã tồn tại!"; // return rs; //} var sv = new tbl_CustomerService() { customerid = customerid, CheckInID = checkinID, SysHotelID = hotelID, productid = productId, productcode = "", datecreated = DateTime.Now, Quantity = quantity, status = 1, }; db.Save(sv, true); //trừ tồn kho tương ứng //trừ tồn kho tương ứng //tìm minibar ứng với phòng đang ở var usingroom = db.Single <tbl_RoomUsing>(x => x.CheckInID == checkinID); var queryStore = db.From <tbl_Store>().Where(e => e.roomid == usingroom.roomid); var firstStore = db.Select(queryStore).FirstOrDefault(); //nếu có kho if (firstStore == null) //nếu ko có kho thì trừ từ kho tổng { firstStore = db.Select(db.From <tbl_Store>() .Where(e => e.typeStore == 1 && e.SysHotelID == comm.GetHotelId())) .FirstOrDefault(); } if (firstStore != null)//nếu có kho thì tiến hành trừ { //duyệt qua các sản phẩm //foreach (var oProduct in product) { var queryProductStore = db.From <tbl_StoreProduct>() .Where(e => e.productid == productId && e.storeid == firstStore.Id) .OrderBy(e => e.quantity); var firstProductInStore = db.Select(queryProductStore).FirstOrDefault(); if (firstProductInStore != null) { firstProductInStore.quantity = firstProductInStore.quantity - quantity; db.Update(firstProductInStore); } } } tran.Commit(); rs.Status = "01"; rs.Data = db.Single <Vw_ProductService>(x => x.CheckinID == checkinID && x.productid == productId && x.cussvID == sv.Id); } return(rs); } } catch (Exception e) { rs.Status = "00"; rs.Message = "Thêm mới dịch vụ thất bại"; return(rs); throw; } }