Example #1
0
        public async Task <JsonResult> MergePartition(int?hotelId, DateTime dateTime)
        {
            FunctionResult result;

            if (hotelId.HasValue)
            {
                Hotel hotel = await YummyOnlineManager.GetHotelById(hotelId.Value);

                result = await new OriginSql(hotel.AdminConnectionString).Merge(dateTime);
            }
            else
            {
                result = await new OriginSql(YummyOnlineManager.ConnectionString).Merge(dateTime);
            }

            if (!result.Succeeded)
            {
                await logPartition(hotelId, nameof(MergePartition), result.Message);

                return(Json(new JsonError(result.Message)));
            }
            await logPartition(hotelId, nameof(MergePartition));

            return(Json(new JsonSuccess()));
        }
Example #2
0
        public async Task <JsonResult> CreateHotel(int hotelId, string databaseName)
        {
            // 创建空数据库
            OriginSql originSql = new OriginSql(new YummyOnlineContext().Database.Connection.ConnectionString);
            var       result    = await originSql.CreateDatabase(databaseName);

            if (!result.Succeeded)
            {
                return(Json(new JsonError(result.Message)));
            }
            // 总数据库记录连接字符串等信息
            await YummyOnlineManager.CreateHotel(hotelId, databaseName);

            // 新数据库写入所有表格等架构
            Hotel newHotel = await YummyOnlineManager.GetHotelById(hotelId);

            originSql = new OriginSql(newHotel.AdminConnectionString);
            result    = await originSql.InitializeHotel();

            if (!result.Succeeded)
            {
                return(Json(new JsonError(result.Message)));
            }

            // 新数据库初始化
            string staffId = await YummyOnlineManager.GetHotelAdminId(hotelId);

            HotelManager hotelManager = new HotelManager(newHotel.AdminConnectionString);
            await hotelManager.InitializeHotel(hotelId, staffId);

            return(Json(new JsonSuccess()));
        }
Example #3
0
        public async Task <JsonResult> ExecuteSql(List <int> hotelIds, string sql)
        {
            StringBuilder sb = new StringBuilder();

            foreach (int id in hotelIds)
            {
                Hotel hotel = await YummyOnlineManager.GetHotelById(id);

                OriginSql      originSql = new OriginSql(hotel.AdminConnectionString);
                FunctionResult result    = await originSql.ExecuteSql(sql);

                if (!result.Succeeded)
                {
                    sb.Append($"{hotel.Name}({hotel.Id}) Error, {result.Message}</br>");
                    await YummyOnlineManager.RecordLog(Log.LogProgram.System, Log.LogLevel.Error, $"Execute SQL {hotel.Name}({hotel.Id}) Failed",
                                                       $"Error: {result.Message}, SQL: {sql}");
                }
                else
                {
                    await YummyOnlineManager.RecordLog(Log.LogProgram.System, Log.LogLevel.Success, $"Execute SQL {hotel.Name}({hotel.Id}) Successfully", sql);
                }
            }
            if (sb.Length != 0)
            {
                return(Json(new JsonError(sb.ToString())));
            }
            return(Json(new JsonSuccess()));
        }
Example #4
0
        public async Task <JsonResult> GetDbPartitionDetailByHotelId(int?hotelId)
        {
            Hotel     hotel;
            OriginSql dbPartition;

            if (hotelId.HasValue)
            {
                hotel = await YummyOnlineManager.GetHotelById(hotelId.Value);

                dbPartition = new OriginSql(hotel.AdminConnectionString);
            }
            else
            {
                hotel       = null;
                dbPartition = new OriginSql(YummyOnlineManager.ConnectionString);
            }

            return(Json(new {
                Hotel = hotel == null ? null : new {
                    hotel.Id,
                    hotel.Name
                },
                DbPartitionInfos = await dbPartition.GetDbPartitionInfos(),
                FileGroupInfos = await dbPartition.GetFileGroupInfos()
            }));
        }
Example #5
0
        // GET: 店小二点菜系统入口 Home/Index/[hotelId]/[qrCode]
        public async Task <ActionResult> Index(int?hotelId, string qrCode)
        {
            if (hotelId == null || qrCode == null)
            {
                if (CurrHotel != null && Session["CurrentDesk"] != null)
                {
                    return(View());
                }
                return(RedirectToAction("HotelMissing", "Error"));
            }

            Hotel hotel = await YummyOnlineManager.GetHotelById(Convert.ToInt32(hotelId));

            if (hotel == null)
            {
                return(RedirectToAction("HotelMissing", "Error"));
            }
            if (!hotel.Usable)
            {
                return(RedirectToAction("HotelUnavailable", "Error"));
            }

            CurrHotel = new CurrHotelInfo(hotel.Id, hotel.ConnectionString);

            Desk desk = await new HotelManager(hotel.ConnectionString).GetDeskByQrCode(qrCode);

            if (desk == null)
            {
                return(RedirectToAction("HotelMissing", "Error"));
            }

            Session["CurrentDesk"] = desk;
            return(View());
        }
Example #6
0
        /// <summary>
        /// 收银员台支付
        /// </summary>
        public async Task <ActionResult> ManagerPay(Cart cart, ManagerCartAddition cartAddition)
        {
            SystemConfig system = await YummyOnlineManager.GetSystemConfig();

            if (system.Token != cartAddition.Token)
            {
                return(Json(new JsonError("身份验证失败")));
            }

            var hotel = await YummyOnlineManager.GetHotelById(cartAddition.HotelId);

            CurrHotel = new CurrHotelInfo(hotel.Id, hotel.ConnectionString);

            if (!hotel.Usable)
            {
                return(RedirectToAction("HotelUnavailable", "Error"));
            }

            cart.PayKindId = await new HotelManager(CurrHotel.ConnectionString).GetOtherPayKindId();
            CartAddition addition = new CartAddition {
                WaiterId     = cartAddition.WaiterId,
                DineType     = cartAddition.DineType,
                Discount     = cartAddition.Discount,
                DiscountName = cartAddition.DiscountName,
                GiftMenus    = cartAddition.GiftMenus,
                From         = DineFrom.Manager
            };

            User user = await UserManager.FindByIdAsync(cartAddition.UserId);

            addition.UserId = user?.Id;

            // 创建新订单
            FunctionResult result = await OrderManager.CreateDine(cart, addition);

            if (!result.Succeeded)
            {
                if (await UserManager.IsInRoleAsync(user.Id, Role.Nemo))
                {
                    await UserManager.DeleteAsync(user);

                    await YummyOnlineManager.RecordLog(YummyOnlineDAO.Models.Log.LogProgram.Identity, YummyOnlineDAO.Models.Log.LogLevel.Warning, $"Anonymous User Deleted {user.Id}, Via Manager");
                }
                await HotelManager.RecordLog(HotelDAO.Models.Log.LogLevel.Error, $"{result.Detail}, Host:{Request.UserHostAddress}", HttpPost.GetPostData(Request));

                return(Json(new JsonError(result.Message)));
            }

            Dine dine = ((Dine)result.Data);

            await newDineInform(dine, "Manager");

            return(Json(new JsonSuccess {
                Data = dine.Id
            }));
        }
Example #7
0
        protected override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            if (CurrHotel != null)
            {
                ViewBag.HotelId      = CurrHotel?.Id;
                ViewBag.CssThemePath = AsyncInline.Run(() => { return(YummyOnlineManager.GetHotelById(CurrHotel.Id)); }).CssThemePath;
            }

            base.OnActionExecuted(filterContext);
        }
Example #8
0
        private async Task logPartition(int?hotelId, string method, string errorMessage)
        {
            if (hotelId.HasValue)
            {
                Hotel hotel = await YummyOnlineManager.GetHotelById(hotelId.Value);

                await YummyOnlineManager.RecordLog(Log.LogProgram.System, Log.LogLevel.Error, $"{method} On {hotel.Name} ({hotel.Id}) Failed, {errorMessage}");
            }
            else
            {
                await YummyOnlineManager.RecordLog(Log.LogProgram.System, Log.LogLevel.Error, $"{method} On YummyOnlineDB Failed, {errorMessage}");
            }
        }
Example #9
0
        private async Task logPartition(int?hotelId, string method)
        {
            if (hotelId.HasValue)
            {
                Hotel hotel = await YummyOnlineManager.GetHotelById(hotelId.Value);

                await YummyOnlineManager.RecordLog(Log.LogProgram.System, Log.LogLevel.Success, $"{method} On {hotel.Name} ({hotel.Id}) Successfully");
            }
            else
            {
                await YummyOnlineManager.RecordLog(Log.LogProgram.System, Log.LogLevel.Success, $"{method} On YummyOnlineDB Successfully");
            }
        }
Example #10
0
        public async Task <JsonResult> Backup(bool isYummyOnline, List <int> hotelIds)
        {
            SystemConfig config = await YummyOnlineManager.GetSystemConfig();

            string path = $"{config.SpecificationDir}\\Database";

            StringBuilder sb = new StringBuilder();

            if (isYummyOnline)
            {
                OriginSql      originSql = new OriginSql(YummyOnlineManager.ConnectionString);
                FunctionResult result    = await originSql.Backup(path);

                if (!result.Succeeded)
                {
                    sb.Append($"YummyOnlineDB Error, {result.Message}</br>");
                    await YummyOnlineManager.RecordLog(Log.LogProgram.System, Log.LogLevel.Error, "Backup YummyOnlineDB Failed", result.Message);
                }
                else
                {
                    await YummyOnlineManager.RecordLog(Log.LogProgram.System, Log.LogLevel.Success, "Backup YummyOnlineDB Successfully");
                }
            }

            foreach (int id in hotelIds)
            {
                Hotel hotel = await YummyOnlineManager.GetHotelById(id);

                OriginSql      originSql = new OriginSql(hotel.AdminConnectionString);
                FunctionResult result    = await originSql.Backup(path);

                if (!result.Succeeded)
                {
                    sb.Append($"{hotel.Name}({hotel.Id}) Error, {result.Message}</br>");
                    await YummyOnlineManager.RecordLog(Log.LogProgram.System, Log.LogLevel.Error, $"Backup {hotel.Name}({hotel.Id}) Failed", result.Message);
                }
                else
                {
                    await YummyOnlineManager.RecordLog(Log.LogProgram.System, Log.LogLevel.Success, $"Backup {hotel.Name}({hotel.Id}) Successfully");
                }
            }
            if (sb.Length != 0)
            {
                return(Json(new JsonError(sb.ToString())));
            }
            return(Json(new JsonSuccess()));
        }
Example #11
0
        /// <summary>
        /// 打印完成
        /// </summary>
        public async Task <JsonResult> PrintCompleted(int hotelId, string dineId)
        {
            CurrHotel = new CurrHotelInfo(await YummyOnlineManager.GetHotelById(hotelId));

            if (dineId == "00000000000000")
            {
                await HotelManager.RecordLog(HotelDAO.Models.Log.LogLevel.Success, $"Print Test Dine Completed");

                return(Json(new JsonSuccess()));
            }

            await OrderManager.PrintCompleted(dineId);

            await HotelManager.RecordLog(HotelDAO.Models.Log.LogLevel.Success, $"PrintCompleted DineId: {dineId}");

            return(Json(new JsonSuccess()));
        }
Example #12
0
        /// <summary>
        /// 支付完成异步通知
        /// </summary>
        public async Task <JsonResult> OnlineNotify(string encryptedInfo)
        {
            string decryptedInfo          = DesCryptography.DesDecrypt(encryptedInfo);
            NetworkNotifyViewModels model = null;

            try {
                model = JsonConvert.DeserializeObject <NetworkNotifyViewModels>(decryptedInfo);
            }
            catch {
                return(Json(new JsonError()));
            }

            CurrHotel = new CurrHotelInfo(await YummyOnlineManager.GetHotelById(model.HotelId));

            await HotelManager.RecordLog(HotelDAO.Models.Log.LogLevel.Info, $"Notified DineId: {model.DineId}");

            await onlinePayCompleted(model.DineId, model.RecordId);

            return(Json(new JsonSuccess()));
        }
Example #13
0
        public async Task <JsonResult> Signin(string signinName, string password)
        {
            Staff staff = await StaffManager.FindStaffBySigninName(signinName);

            if (staff == null)
            {
                await YummyOnlineManager.RecordLog(Log.LogProgram.Identity, Log.LogLevel.Warning, $"Staff Signin: {signinName} No SigninName, Host: {Request.UserHostAddress}");

                return(Json(new JsonError("没有此登录名")));
            }
            if (!await StaffManager.CheckPasswordAsync(staff, password))
            {
                await YummyOnlineManager.RecordLog(Log.LogProgram.Identity, Log.LogLevel.Warning, $"Staff Signin: {signinName} Password Error, Host: {Request.UserHostAddress}",
                                                   $"Password: {password}");

                return(Json(new JsonError("密码不正确")));
            }

            Hotel hotel = await YummyOnlineManager.GetHotelById(staff.HotelId);

            if (!hotel.Usable)
            {
                return(Json(new JsonError("该饭店不可用,请联系管理员")));
            }
            CurrHotel = hotel;

            if (!await HotelManager.IsStaffHasSchema(staff.Id, HotelDAO.Models.Schema.ReadWaiterData))
            {
                await YummyOnlineManager.RecordLog(Log.LogProgram.Identity, Log.LogLevel.Warning, $"Staff Signin: {staff.Id} (HotelId {staff.HotelId}) No Authority, Host: {Request.UserHostAddress}");

                return(Json(new JsonError("没有权限")));
            }
            SigninManager.Signin(staff, true);
            await YummyOnlineManager.RecordLog(Log.LogProgram.Identity, Log.LogLevel.Success, $"Staff Signin: {staff.Id} (HotelId {staff.HotelId}), Host: {Request.UserHostAddress}");

            return(Json(new JsonSuccess {
                Data = staff.Id
            }));
        }
Example #14
0
        public async Task <JsonResult> GetHotelLogs(int?hotelId, DateTime dateTime, int?count)
        {
            Hotel hotel;

            if (hotelId.HasValue)
            {
                hotel = await YummyOnlineManager.GetHotelById(hotelId.Value);
            }
            else
            {
                hotel = await YummyOnlineManager.GetFirstHotel();
            }

            HotelManager manager = new HotelManager(hotel.ConnectionString);

            return(Json(new {
                Hotel = new {
                    Id = hotel.Id,
                    Name = hotel.Name
                },
                Logs = await manager.GetLogs(dateTime, count)
            }));
        }
Example #15
0
 public async Task <ActionResult> _ViewMenu()
 {
     ViewBag.OrderSystemStyle = (await YummyOnlineManager.GetHotelById(CurrHotel.Id)).OrderSystemStyle;
     return(View());
 }