//private async Task<IActionResult> LoadGrid(string[] Grid1_fields, int Grid1_pageIndex, string Grid1_sortField, string Grid1_sortDirection, string ttbSearchMessage, int ddlGridPageSize, string actionType)
        //{
        //    var grid1UI = UIHelper.Grid("Grid1");
        //    var pagingInfo = new PagingInfoViewModel
        //    {
        //        SortField = Grid1_sortField,
        //        SortDirection = Grid1_sortDirection,
        //        PageIndex = Grid1_pageIndex,
        //        PageSize = ddlGridPageSize
        //    };

        //    var users = await GetDataAsync(pagingInfo, ttbSearchMessage);
        //    // 1. 设置总项数
        //    grid1UI.RecordCount(pagingInfo.RecordCount);
        //    // 2. 设置每页显示项数
        //    if (actionType == "changeGridPageSize")
        //    {
        //        grid1UI.PageSize(ddlGridPageSize);
        //    }
        //    // 3.设置分页数据
        //    grid1UI.DataSource(users, Grid1_fields);

        //    return UIHelper.Result();
        //}

        public async Task <IActionResult> OnPostSaveDataAsync(string[] Grid1_fields, JArray Grid1_modifiedData, int Grid1_pageIndex, string Grid1_sortField, string Grid1_sortDirection,
                                                              string ttbSearchMessage, int ddlGridPageSize, string actionType)
        {
            foreach (JObject modifiedRow in Grid1_modifiedData)
            {
                string status = modifiedRow.Value <string>("status");
                int    rowId  = Convert.ToInt32(modifiedRow.Value <string>("id"));

                if (status == "modified")
                {
                    var owner = ParkDB.CarOwners.Find(rowId);
                    if (modifiedRow["values"]["Enabled"] != null)
                    {
                        owner.Enabled = modifiedRow["values"]["Enabled"].Value <bool>();
                    }
                    if (modifiedRow["values"]["IsFree"] != null)
                    {
                        owner.IsFree = modifiedRow["values"]["IsFree"].Value <bool>();
                    }
                    ParkDB.Entry(owner).State = EntityState.Modified;
                }
            }
            await ParkDB.SaveChangesAsync();

            ShowNotify("数据保存成功!");

            return(await LoadGrid(Grid1_fields, Grid1_pageIndex, Grid1_sortField, Grid1_sortDirection, ttbSearchMessage, ddlGridPageSize, actionType));
        }
        /// <summary>
        /// adds item to wish to vist list
        /// </summary>
        /// <param name="id"></param>
        /// <param name="previosUrl"></param>
        /// <returns></returns>
        public async Task <IActionResult> AddWishToVisit(int id, string previosUrl)
        {
            // Get product from the database
            ParkModel p = await ParkDB.GetProductAsync(_context, id);

            // redirct back to prevoius page
            return(Redirect(previosUrl));
        }
Example #3
0
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            ParkModel p = await ParkDB.GetProductAsync(_context, id);

            _context.Entry(p).State = EntityState.Deleted;

            await _context.SaveChangesAsync();

            TempData["Message"] = $"{p.ParkName} was deleted";

            return(RedirectToAction("Index"));
        }
Example #4
0
        public async Task <IActionResult> Add(ParkModel p)
        {
            if (ModelState.IsValid)
            {
                p = await ParkDB.AddProductAsync(_context, p);

                TempData["Message"] = $"{p.ParkName} was added successfully";


                return(RedirectToAction("Index"));
            }

            return(View());
        }
Example #5
0
        public async Task <IActionResult> OnPostDoPostBackAsync(string[] Grid1_fields, int Grid1_pageIndex, string Grid1_sortField, string Grid1_sortDirection,
                                                                string ttbSearchMessage, string rblEnableStatus, int ddlGridPageSize, string actionType, int[] deletedRowIDs)
        {
            List <int> ids = new List <int>();

            if (deletedRowIDs != null)
            {
                ids.AddRange(deletedRowIDs);
            }

            var ttbSearchMessageUI = UIHelper.TwinTriggerBox("ttbSearchMessage");

            if (actionType == "trigger1")
            {
                ttbSearchMessageUI.Text(String.Empty);
                ttbSearchMessageUI.ShowTrigger1(false);

                // 清空传入的搜索值
                ttbSearchMessage = String.Empty;
            }
            else if (actionType == "trigger2")
            {
                ttbSearchMessageUI.ShowTrigger1(true);
            }
            else if (actionType == "delete")
            {
                DbSets.Where(u => ids.Contains(u.ID)).ToList().ForEach(u => DbSets.Remove(u));
                await ParkDB.SaveChangesAsync();
            }
            //else if (actionType == "enable")
            //{
            //    DbSets.Where(u => ids.Contains(u.ID)).ToList().ForEach(u => u.Enabled = true);
            //    await DB.SaveChangesAsync();
            //}
            //else if (actionType == "pswd")
            //{
            //    foreach (var owner in DbSets.Where(u => ids.Contains(u.ID)).ToList())
            //    {
            //        await CarOwnerService.SetPasswordAsync(ParkDB, owner, "123456");
            //    }
            //    ShowNotify("已重设密码为123456");
            //    await DB.SaveChangesAsync();
            //}
            OtherPostBack(actionType, ids);
            await OtherPostBackAsync(actionType, ids);

            return(await LoadGrid(Grid1_fields, Grid1_pageIndex, Grid1_sortField, Grid1_sortDirection, ttbSearchMessage, ddlGridPageSize, actionType));
        }
Example #6
0
        /// <summary>
        /// How mnay parks per page
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <IActionResult> Index(int?id)
        {
            int       pageNum  = id ?? 1;
            const int PageSize = 20;

            ViewData["CurrentPage"] = pageNum;

            int numProducts = await ParkDB.GetTotalProductsAsync(_context);

            int totalPages = (int)Math.Ceiling((double)numProducts / PageSize);

            ViewData["MaxPage"] = totalPages;

            List <ParkModel> products = await ParkDB.GetProductsAsync(_context, PageSize, pageNum);



            return(View(products));
        }
        /// <summary>
        /// Adds item to visited list
        /// </summary>
        /// <param name="id"></param>
        /// <param name="previosUrl"></param>
        /// <returns></returns>
        public async Task <IActionResult> AddVisited(int id, string previosUrl)
        {
            // Get product from the database
            ParkModel p = await ParkDB.GetProductAsync(_context, id);

            List <ParkModel> parks = CookieHelper.GetCartProducts(_httpContext);

            // stops same park from ebing added again
            if (parks.Contains(p))
            {
                TempData["Message"] = p.ParkName + " was already added successfully";
            }
            else
            {
                CookieHelper.AddProductToCart(_httpContext, p);
                TempData["Message"] = p.ParkName + " was added successfully";
            }
            // redirct back to prevoius page
            return(Redirect(previosUrl));
        }
Example #8
0
        public async Task <IActionResult> OnPostSaveDataAsync(string[] Grid1_fields, JArray Grid1_modifiedData, int Grid1_pageIndex, string Grid1_sortField, string Grid1_sortDirection,
                                                              string ttbSearchMessage, int ddlGridPageSize, string actionType)
        {
            foreach (JObject modifiedRow in Grid1_modifiedData)
            {
                string status = modifiedRow.Value <string>("status");
                int    rowId  = Convert.ToInt32(modifiedRow.Value <string>("id"));

                if (status == "modified")
                {
                    var ps = ParkDB.ParkAreas.Find(rowId);
                    ps.GateTokens          = modifiedRow["values"]["GateTokens"].Value <string>();
                    ParkDB.Entry(ps).State = EntityState.Modified;
                }
            }
            await ParkDB.SaveChangesAsync();

            ShowNotify("数据保存成功!");

            return(await LoadGrid(Grid1_fields, Grid1_pageIndex, Grid1_sortField, Grid1_sortDirection, ttbSearchMessage, ddlGridPageSize, actionType));
        }
Example #9
0
        public async Task <IActionResult> Edit(int id)
        {
            ParkModel p = await ParkDB.GetProductAsync(_context, id);

            return(View(p));
        }