protected void Application_End() { var logs = new YummyOnlineDAO.Models.Log(); logs.Program = YummyOnlineDAO.Models.Log.LogProgram.Manager; logs.Level = YummyOnlineDAO.Models.Log.LogLevel.Error; logs.DateTime = DateTime.Now; logs.Message = $"Thread was killed"; var db = new YummyOnlineContext(); db.Logs.Add(logs); db.SaveChanges(); }
public JsonResult Register(string Name, string Phone, string PassWord, string Key) { if (Key != Session["Key"] as string) { return(Json(new ErrorState("验证码不正确"))); } else { var rs = new YummyOnlineContext(); var repeat = rs.Hotels.Where(h => h.Tel == Phone && h.Usable == true).FirstOrDefault(); if (repeat != null) { return(Json(new ErrorState("该号码已被注册"))); } var Staff = rs.Staffs.Where(d => d.SigninName == Phone).FirstOrDefault(); if (Staff != null) { return(Json(new ErrorState("该号码已被注册"))); } var NewHotel = new Hotel { Address = "默认", ConnectionString = null, CreateDate = DateTime.Now, Tel = Phone, AdminConnectionString = null, Usable = false, OpenTime = new TimeSpan(8, 0, 0), CloseTime = new TimeSpan(20, 0, 0), Name = Name, CssThemePath = "default.css", Id = rs.Hotels.Max(h => h.Id) + 1 }; rs.Hotels.Add(NewHotel); rs.SaveChanges(); var ps = Method.GetMd5(PassWord); rs.Staffs.Add(new YummyOnlineDAO.Models.Staff { HotelId = NewHotel.Id, CreateDate = DateTime.Now, PasswordHash = ps, PhoneNumber = Phone, SigninName = Phone, IsHotelAdmin = true }); rs.SaveChanges(); return(Json(new SuccessState())); } }
private async Task changeCustomerPoints(Dine dine) { // 用户总平台消费金额 var yummyonlineCtx = new YummyOnlineContext(); User user = await yummyonlineCtx.Users.FirstOrDefaultAsync(p => p.Id == dine.UserId); if (user == null) { return; } user.Price += dine.Price; await yummyonlineCtx.SaveChangesAsync(); Customer customer = await ctx.Customers.FirstOrDefaultAsync(p => p.Id == dine.UserId); // 如果用户不存在或者是匿名用户 if (customer == null || await new UserManager().IsInRoleAsync(dine.UserId, Role.Nemo)) { return; } // 如果使用的积分支付 DinePaidDetail pointsPaidDetail = await ctx.DinePaidDetails.FirstOrDefaultAsync(p => p.Dine.Id == dine.Id && p.PayKind.Type == PayKindType.Points); if (pointsPaidDetail != null) { HotelConfig config = await ctx.HotelConfigs.FirstOrDefaultAsync(); customer.Points -= Convert.ToInt32((double)pointsPaidDetail.Price / config.PointsRatio); } // 用户点过的菜品增加积分 List <DineMenu> dineMenus = await ctx.DineMenus.Include(p => p.Menu.MenuPrice).Where(p => p.Dine.Id == dine.Id).ToListAsync(); dineMenus?.ForEach(m => { customer.Points += m.Menu.MenuPrice.Points * m.Count; }); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); RouteConfig.RegisterRoutes(RouteTable.Routes); ws.start(); string guid = ConfigurationManager.AppSettings["guid"]; var db = new YummyOnlineContext(); var tcp = db.SystemConfigs.Select(sys => new { sys.TcpServerIp, sys.TcpServerPort }).ToList(); client = new TcpClient( IPAddress.Parse(tcp.FirstOrDefault()?.TcpServerIp), tcp.FirstOrDefault().TcpServerPort, new NewDineInformClientConnectProtocol(guid) ); client.CallBackWhenMessageReceived = async(t, p) => { if (t != TcpProtocolType.NewDineInform) { return; } NewDineInformProtocol protocol = (NewDineInformProtocol)p; string Cstr = await(db.Hotels.Where(h => h.Id == protocol.HotelId).Select(h => h.ConnectionString)).FirstOrDefaultAsync(); var hotel = new HotelContext(Cstr); var temp = await hotel.Dines.Where(dine => dine.Id == protocol.DineId).Select(dine => new { dine.DeskId, dine.IsOnline }).FirstOrDefaultAsync(); if (!temp.IsOnline) { var desk = hotel.Desks.FirstOrDefault(d => d.Id == temp.DeskId); desk.Status = DeskStatus.Used; var clean = await hotel.Dines.Where(d => d.DeskId == desk.Id && d.IsOnline == false && d.IsPaid == false).ToListAsync(); if (clean.Count() == 0) { desk.Status = DeskStatus.StandBy; } hotel.SaveChanges(); await ws.SendToClient(protocol.HotelId, "desk"); await ws.SendToClient(protocol.HotelId, "dine"); } }; client.CallBackWhenConnected = () => { Console.WriteLine("Connected"); }; client.CallBackWhenExceptionOccured = u => { Console.WriteLine(u); }; client.Start(); var url = db.SystemConfigs.FirstOrDefault() == null?"127.0.0.1": db.SystemConfigs.FirstOrDefault().ManagementUrl; var ordUrl = db.SystemConfigs.FirstOrDefault() == null ? "http://ordersystem.yummyonline.net" : db.SystemConfigs.FirstOrDefault().OrderSystemUrl; System.Timers.Timer timer = new System.Timers.Timer(1000 * 60 * 10); timer.Elapsed += new System.Timers.ElapsedEventHandler(async(a, b) => { await Method.postHttp(url, new { }); await Method.postHttp(ordUrl, new{ }); }); //到达时间的时候执行事件; timer.AutoReset = true; //设置是执行一次(false)还是一直执行(true); timer.Enabled = true; //是否执行System.Timers.Timer.Elapsed事件; timer.Start(); }
public UserManager() { ctx = new YummyOnlineContext(); }
protected async Task <string> AsyncChange(int HotelId, string cg) { JsonSerializerSettings setting = new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }; string ConnectingStr; using (var db = new YummyOnlineContext()) { ConnectingStr = db.Hotels.Where(h => h.Id == HotelId).Select(h => h.ConnectionString).FirstOrDefault(); } using (var db = new HotelContext(ConnectingStr)) { if (cg == "desk") { var data = await db.Desks.Where(d => d.Usable == true) .Select(d => new { d.AreaId, d.Name, d.Status, d.Id, d.Order }).OrderBy(d => d.Order).ToListAsync(); return(JsonConvert.SerializeObject(new { HotelId = HotelId, change = "desk", data = data }, setting)); } else if (cg == "dine") { var Orders = await db.Dines .Include(p => p.DineMenus.Select(pp => pp.Remarks)) .Include(p => p.DineMenus.Select(pp => pp.Menu.MenuPrice)) .Where(order => order.IsPaid == false && order.IsOnline == false) .Select(d => new { d.Discount, d.DiscountName, d.Id, DineMenus = d.DineMenus.Select(dd => new { Count = dd.Count, DineId = dd.DineId, Id = dd.Id, Menu = dd.Menu, MenuId = dd.MenuId, OriPrice = dd.OriPrice, Price = dd.Price, RemarkPrice = dd.RemarkPrice, Remarks = dd.Remarks, ReturnedWaiterId = dd.ReturnedWaiterId, Status = dd.Status, Type = dd.Type }), Menu = d.DineMenus.Select(dd => new { dd.Menu, dd.Menu.MenuPrice }), d.BeginTime, d.DeskId, d.Remarks, d.HeadCount, d.UserId, d.OriPrice, d.Price }) .ToListAsync(); return(JsonConvert.SerializeObject(new { HotelId = HotelId, change = "dine", data = Orders }, setting)); } else { return(null); } } }
/// <summary> /// 登陆验证 /// </summary> /// <returns>验证信息</returns> public async Task <JsonResult> Verification(RemoteUser User) { RStatus rs; string ConnectingStr; using (var db = new YummyOnlineContext()) { string PasswordHash = Method.GetMd5(User.password); var clerk = db.Staffs.Where(ck => ck.SigninName == User.username && ck.PasswordHash == PasswordHash); var ClerkInfo = await clerk.FirstOrDefaultAsync(); int?Hotel = clerk.FirstOrDefault()?.HotelId; ConnectingStr = db.Hotels.Where(ht => ht.Id == Hotel).First().ConnectionString; Session["ConnectString"] = ConnectingStr; var hotel = new HotelContext(ConnectingStr); rs = clerk.Count() > 0 ? new RStatus { Status = true, HotelId = ClerkInfo.HotelId, Name = hotel.Staffs.Where(s => s.Id == ClerkInfo.Id).Select(s => s.Name).FirstOrDefault(), ClerkId = ClerkInfo.Id } : new RStatus { Status = false }; var logs = new YummyOnlineDAO.Models.Log(); logs.DateTime = DateTime.Now; logs.Level = YummyOnlineDAO.Models.Log.LogLevel.Success; logs.Program = YummyOnlineDAO.Models.Log.LogProgram.Identity; logs.Message = $"Manager Signin: {ClerkInfo.Id} (HotelId {ClerkInfo.HotelId}), Host: {Request.UserHostAddress}"; db.Logs.Add(logs); db.SaveChanges(); } using (var db = new HotelContext(ConnectingStr)) { if (rs.Status) { FormsAuthentication.SetAuthCookie(User.username, false); int[] roles = (from s in db.Staffs from r in s.StaffRoles where s.Id == rs.ClerkId select r.Id).ToArray(); var models = from r in db.StaffRoles from s in r.Schemas where roles.Contains(r.Id) select s.Schema; int Rate = db.HotelConfigs.Select(h => h.PointsRatio).FirstOrDefault(); Session["Rate"] = Rate; rs.IsStaffPay = 0; rs.IsStaffReturn = 0; rs.IsStaffEdit = 0; foreach (var m in models) { if (m == Schema.StaffPay) { rs.IsStaffPay = 1; } else if (m == Schema.StaffReturn) { rs.IsStaffReturn = 1; } else if (m == Schema.StaffEdit) { rs.IsStaffEdit = 1; } else { } } } else { } } Session["User"] = rs; Session["Username"] = User.username; return(await Task.Run(() => Json(rs))); }