Exemplo n.º 1
0
        public IResponseBase Execute(IRequestParameter parameters)
        {
            var result = new Response <MenuResponse>();

            try
            {
                _request = (MenuRequest)parameters;
                _isRoot  = _request.Url.Equals(Config.Params.HrefPrefix + "root");
                result   = CacheMemory.Get <Response <MenuResponse> >(Config.CacheKeys.Menu);
                if (result == null || string.IsNullOrWhiteSpace(result.template))
                {
                    if (_request.Url.StartsWith(Config.Params.HrefPrefix))
                    {
                        _request.Url = _request.Url.Remove(0, Config.Params.HrefPrefix.Length);
                    }
                    var config = BuildAPIConfig(parameters);
                    result          = GetResponse(config);
                    result.template = Config.ResponseTemplates.Menu;
                    if (_isRoot && _errors.Count == 0)
                    {
                        CacheMemory.SetAndExpiresHoursAsync(Config.CacheKeys.Menu, result, 4);
                    }
                }
            }
            catch (Exception ex)
            {
                if (_isRoot)
                {
                    _errors.Add(ex.Handle("Menu.Execute", ErrorSeverity.FollowUp, ErrorType.RequestError));
                }
            }
            return(result);
        }
Exemplo n.º 2
0
        public async Task <string> GivenAMenuAlreadyExists()
        {
            createMenuRequest = new MenuRequestBuilder()
                                .SetDefaultValues("Yumido Test Menu")
                                .Build();

            try
            {
                lastResponse = await HttpRequestFactory.Post(baseUrl, menuPath, createMenuRequest);

                if (lastResponse.StatusCode == HttpStatusCode.Created)
                {
                    existingMenuId = JsonConvert
                                     .DeserializeObject <CreateObjectResponse>(await lastResponse.Content.ReadAsStringAsync()).id;
                }
                else
                {
                    throw new Exception();
                }
            }
            catch
            {
                throw new Exception(
                          $"Menu could not be created. API response: {await lastResponse.Content.ReadAsStringAsync()}");
            }

            return(existingMenuId);
        }
Exemplo n.º 3
0
 private void SetMenuItems(Response <MenuResponse> result)
 {
     foreach (var menuItem in result.resultset.Menu)
     {
         try
         {
             var item = menuItem;
             if (menuItem.Subs.Count <= 0)
             {
                 continue;
             }
             foreach (var sub in menuItem.Subs)
             {
                 var menu        = new Menu(_core, _errors);
                 var menuRequest = new MenuRequest
                 {
                     Url            = sub.CategoryId,
                     Path           = item.Name.ToLower().Replace(" ", "-"),
                     KeepTraversing = false
                 };
                 var menuSubItems = GetSubMenu(sub, menu, menuRequest);
                 if (menuSubItems.Count > 0)
                 {
                     sub.Subs = menuSubItems;
                 }
             }
         }
         catch (Exception e)
         {
             //todo report to relic
             //do not block
         }
     }
 }
Exemplo n.º 4
0
        public Response <int> updateMenu(MenuRequest request)
        {
            Response <int> response = new Response <int>();


            if (request.Id > 0)
            {
                var data      = this.Db.Menus.SingleOrDefault(a => a.Id == request.Id);
                var getParent = this.Db.Menus.SingleOrDefault(a => a.Id == request.ParentMenu);

                data.Title = request.Title;

                data.Description  = request.Description;
                data.IsFolder     = request.IsFolder;
                data.Css          = request.Css;
                data.Icon         = request.Icon;
                data.IsMobile     = request.IsMobile;
                data.ParentMenu   = getParent;
                data.UISRef       = request.UISRef;
                data.ModifiedBy   = request.UserLogin;
                data.ModifiedDate = DateTime.Now;

                this.Db.Menus.Update(data);
                this.Db.SaveChanges();
                response.data = data.Id;
            }

            return(response);
        }
Exemplo n.º 5
0
        public Response <int> createMenu(MenuRequest request)
        {
            Response <int> response = new Response <int>();

            var  getParent = this.Db.Menus.SingleOrDefault(a => a.Id == request.ParentMenu);
            Menu menu      = new Menu {
                Title        = request.Title,
                Description  = request.Description,
                IsFolder     = request.IsFolder,
                Css          = request.Css,
                Icon         = request.Icon,
                IsMobile     = request.IsMobile,
                ParentMenu   = getParent,
                UISRef       = request.UISRef,
                CreatedBy    = request.UserLogin,
                CreatedDate  = DateTime.Now,
                ModifiedDate = DateTime.Now,
                ModifiedBy   = request.UserLogin
            };

            this.Db.Menus.Add(menu);
            this.Db.SaveChanges();

            response.data = menu.Id;

            return(response);
        }
Exemplo n.º 6
0
        public async Task <MenuResponse> CreateAsync(MenuRequest request)
        {
            var menu = _mapper.Map <Menu>(request);
            await _unitOfWork.Menus.AddMenuAsync(menu);

            await _unitOfWork.SaveAsync();

            return(_mapper.Map <MenuResponse>(menu));
        }
Exemplo n.º 7
0
        private async void getMenus()
        {
            /*AddFavoritePageView = new AddFavoritePageView(new List<FavoritePage>(FavoriteMenuViewModel.FavoritePages));
             * AddFavoritePageView.OperationCompleted += SecondaryPage_OperationCompleted;
             * await Navigation.PushAsync(AddFavoritePageView);*/

            ShowLoading();

            MenuRequest menuRequest = new MenuRequest
            {
                profile = "CONSULTA1"
            };

            var    jsonRequest = JsonConvert.SerializeObject(menuRequest);
            var    content     = new StringContent(jsonRequest, Encoding.UTF8, "text/json");
            var    response    = new Response();
            string result;

            //envio

            try
            {
                response = await ApiService.ConsumoPOST(ApiService.URL, "/apiRPC/api/Menu/Socket", content);

                result = response.Result;
            }
            catch
            {
            }

            if (response.Code >= 400)
            {
                if (response.Code == 401)
                {
                    Settings.JwtToken = "";
                    RefreshToken();
                    if (IsRefreshed)
                    {
                        getMenus();
                    }
                    return;
                }
                else
                {
                    ShowErrorMessage(response.Message);
                    HideLoading();
                    return;
                }
            }
            else if (response.Code >= 200 && response.Code < 300)
            {
                List <Models.Menu.MenuItem> menuItems = JsonConvert.DeserializeObject <List <Models.Menu.MenuItem> >(response.Result);
                HideLoading();
                ShowSuccessMessage("Exito!");
            }
        }
Exemplo n.º 8
0
        public async Task WhenISendAnUpdateMenuRequest()
        {
            updateMenuRequest = new MenuRequestBuilder()
                                .WithName("Updated Menu Name")
                                .WithDescription("Updated Description")
                                .SetEnabled(true)
                                .Build();

            lastResponse = await HttpRequestFactory.Put(baseUrl, $"{menuPath}{existingMenuId}", updateMenuRequest);
        }
Exemplo n.º 9
0
        /// <summary>
        /// 修改菜单
        /// PC
        /// </summary>
        /// <returns></returns>
        public bool ModifyMenu(MenuRequest request)
        {
            var obj = _projectMenuRepository.GetById(request.Id);

            obj.FunctionName = request.FunctionName;
            obj.FunctionKey  = request.FunctionKey;
            obj.FunctionUrl  = request.FunctionUrl;
            obj.Icon         = request.Icon;
            obj.DisplayNo    = request.DisplayNo;
            return(_projectMenuRepository.SaveChanges());
        }
Exemplo n.º 10
0
        /// <summary>
        /// Get menu details
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public MenuResponse GetDetail(MenuRequest request)
        {
            MenuResponse response = new MenuResponse();

            var qry = _unitOfWork.MenuRepository.Query(x => x.ID == request.Data.Id, null);

            if (qry.FirstOrDefault() != null)
            {
                response.Entity = Mapper.Map <Menu, MenuModel>(qry.FirstOrDefault());
            }

            return(response);
        }
Exemplo n.º 11
0
        private static List <MenuItem> GetSubMenu(MenuItem sub, Menu menu, MenuRequest menuRequest)
        {
            List <MenuItem> menuList;

            try
            {
                menuList = ((Response <MenuResponse>)menu.Execute(menuRequest)).resultset.Menu;
            }
            catch (Exception)
            {
                return(new List <MenuItem>());
            }
            return(menuList);
        }
Exemplo n.º 12
0
 public CreateResponse Create(MenuRequest request)
 {
     try
     {
         var menu = TypeAdapter.Adapt <Menu>(request);
         _menuValidator.ValidateAndThrowException(menu, "Base,Create");
         _menuRepository.Add(menu);
         return(new CreateResponse(menu.Id));
     }
     catch (DataAccessException)
     {
         throw new ApplicationException();
     }
 }
Exemplo n.º 13
0
 private void SetMenuAndBrands()
 {
     try
     {
         var menu         = new Menu(_core, _errors);
         var menuRequest  = new MenuRequest();
         var menuResponse = menu.Execute(menuRequest);
         _result.resultset.Menu = ((Response <MenuResponse>)menuResponse).resultset.Menu;
         _result.resultset.AllBrandsBreakdown = FormatBrands(_result.resultset.Menu.Where(a => a.Name == "Brands").ToList());
     }
     catch (Exception ex)
     {
         _result.errors.Add(ex.Handle("Init.SetMenuAndBrands: " + ex, ErrorSeverity.FollowUp, ErrorType.RequestError));
     }
 }
Exemplo n.º 14
0
        public Response <int> deleteMenu(MenuRequest request)
        {
            Response <int> response = new Response <int>();


            if (request.Id > 0)
            {
                var data = this.Db.Menus.SingleOrDefault(a => a.Id == request.Id);
                this.Db.Menus.Remove(data);
                this.Db.SaveChanges();
                response.data = data.Id;
            }

            return(response);
        }
Exemplo n.º 15
0
        public async Task UpdateAsync(long Id, MenuRequest request)
        {
            var menu = await _unitOfWork.Menus.GetMenuOnlyByIdAsync(Id);

            if (menu != null)
            {
                menu.Name = request.Name;
                _unitOfWork.Menus.UpdateMenu(menu);
                await _unitOfWork.SaveAsync();
            }
            else
            {
                throw new EntityNotFoundException($"Menu Id '{Id}' not found.");
            }
        }
Exemplo n.º 16
0
        public HttpResponseMessage add_projectmenu(MenuRequest request)
        {
            if (request == null)
            {
                return(toJson(null, OperatingState.CheckDataFail, "未传入需要的条件"));
            }
            //判断是否存在
            if (_menuOrButtonService.IsExists(request))
            {
                return(toJson(null, OperatingState.CheckDataFail, "已经存在该菜单"));
            }

            var result = _menuOrButtonService.AddMenu(request);

            return(result ? toJson(null, OperatingState.Success, "操作成功") : toJson(null, OperatingState.Failure, "操作失败"));
        }
Exemplo n.º 17
0
        public void Put([FromForm] MenuRequest request, long id)
        {
            var menu = _context.Menu.Find(id);

            menu.M1  = request.m1;
            menu.M2  = request.m2;
            menu.M3  = request.m3;
            menu.M4  = request.m4;
            menu.M5  = request.m5;
            menu.M6  = request.m6;
            menu.M7  = request.m7;
            menu.M8  = request.m8;
            menu.M9  = request.m9;
            menu.M10 = request.m10;
            menu.M11 = request.m11;
            menu.M12 = request.m12;
            menu.M13 = request.m13;
            menu.M14 = request.m14;
            menu.M15 = request.m15;
            menu.M16 = request.m16;
            menu.M17 = request.m17;
            menu.M18 = request.m18;
            menu.M19 = request.m19;
            menu.M20 = request.m20;
            menu.M21 = request.m21;
            menu.M22 = request.m22;
            menu.M23 = request.m23;
            menu.M24 = request.m24;
            menu.M25 = request.m25;
            menu.M26 = request.m26;
            menu.M27 = request.m27;
            menu.M28 = request.m28;
            menu.M29 = request.m29;
            menu.M30 = request.m30;
            menu.M31 = request.m31;
            menu.M32 = request.m32;
            menu.M33 = request.m33;
            menu.M34 = request.m34;


            _context.Entry(menu).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            _context.SaveChanges();

            System.Console.WriteLine("testmenu : " + request.m7);
        }
Exemplo n.º 18
0
 /// <summary>
 /// Entry point to the console application.
 /// </summary>
 /// <param name="args">Arguments to program running</param>
 private static void Main(string[] args)
 {
     Log.Logger = new LoggerConfiguration().WriteTo.File(logFile).CreateLogger();
     while (true)
     {
         try
         {
             Menu.DisplayMenu();
             MenuRequest req = Menu.PromptUser();
             MenuHandler.HandleRequest(req);
         }
         catch (Exception ex)
         {
             Console.WriteLine($"{ex.Message}\n");
             Log.Error(ex.Message);
         }
     }
 }
Exemplo n.º 19
0
        /// <summary>
        /// Validate request
        /// </summary>
        /// <param name="request"></param>
        /// <param name="response"></param>
        public void Validate(MenuRequest request, out MenuResponse response)
        {
            response = new MenuResponse();

            if (request.Action != null && request.Action.Equals(ClinicEnums.Action.DELETE.ToString()))
            {
                ValidateForDelete(request, out response);
            }
            else
            {
                bool isHavePrivilege = true;

                if (request.Data.Name == null || String.IsNullOrWhiteSpace(request.Data.Name))
                {
                    errorFields.Add("Menu Name");
                }

                if (errorFields.Any())
                {
                    response.Status  = false;
                    response.Message = string.Format(Messages.ValidationErrorFields, String.Join(",", errorFields));
                }

                if (request.Data.Id == 0)
                {
                    isHavePrivilege = IsHaveAuthorization(ADD_PRIVILEGE_NAME, request.Data.Account.Privileges.PrivilegeIDs);
                }
                else
                {
                    isHavePrivilege = IsHaveAuthorization(EDIT_PRIVILEGE_NAME, request.Data.Account.Privileges.PrivilegeIDs);
                }

                if (!isHavePrivilege)
                {
                    response.Status  = false;
                    response.Message = Messages.UnauthorizedAccess;
                }

                if (response.Status)
                {
                    response = new MenuHandler(_unitOfWork).CreateOrEdit(request);
                }
            }
        }
Exemplo n.º 20
0
        /// <summary>
        /// 查询列表(分页)
        /// </summary>
        public IEnumerable <Menu> GetMenuPageList(MenuRequest request = null)
        {
            request = request ?? new MenuRequest();
            using (var dbContext = new AccountDbContext())
            {
                IQueryable <Menu> queryList = dbContext.Menus.Include("Parent").Where(o => o.ID != _RootMenuId);

                if (!string.IsNullOrEmpty(request.Name))
                {
                    queryList = queryList.Where(o => o.Name.Contains(request.Name));
                }
                if (request.ParentId.HasValue)
                {
                    queryList = queryList.Where(o => o.ParentId == request.ParentId);
                }

                return(queryList.OrderBy(u => u.Orderby).ToPagedList(request.PageIndex, request.PageSize));
            }
        }
Exemplo n.º 21
0
        /// <summary>
        /// Delete validation
        /// </summary>
        /// <param name="request"></param>
        /// <param name="response"></param>
        private void ValidateForDelete(MenuRequest request, out MenuResponse response)
        {
            response = new MenuResponse();

            if (request.Action == ClinicEnums.Action.DELETE.ToString())
            {
                bool isHavePrivilege = IsHaveAuthorization(DELETE_PRIVILEGE_NAME, request.Data.Account.Privileges.PrivilegeIDs);
                if (!isHavePrivilege)
                {
                    response.Status  = false;
                    response.Message = Messages.UnauthorizedAccess;
                }
            }

            if (response.Status)
            {
                response = new MenuHandler(_unitOfWork).RemoveData(request);
            }
        }
Exemplo n.º 22
0
        public async Task <IActionResult> UpdateMenu(long Id, [FromBody] MenuRequest request)
        {
            if (ModelState.IsValid)
            {
                await _menuService.UpdateAsync(Id, request);

                return(StatusCode(204, new ApiResponse
                {
                    Status = true,
                    Message = "Success"
                }));
            }
            return(BadRequest(
                       new ApiResponse
            {
                Status = false,
                Message = "Validation Failure"
            }));
        }
Exemplo n.º 23
0
 public SuccessResponse Update(MenuRequest request)
 {
     try
     {
         var currentMenu = _menuRepository.FindBy(request.Id);
         currentMenu.ThrowExceptionIfRecordIsNull();
         var menuToCopy = TypeAdapter.Adapt <Menu>(request);
         TypeAdapter.Adapt(menuToCopy, currentMenu);
         _menuValidator.ValidateAndThrowException(currentMenu, "Base,Update");
         _menuRepository.Update(currentMenu);
         return(new SuccessResponse {
             IsSuccess = true
         });
     }
     catch (DataAccessException)
     {
         throw new ApplicationException();
     }
 }
Exemplo n.º 24
0
        /// <summary>
        /// 添加菜单
        /// PC
        /// </summary>
        /// <returns></returns>
        public bool AddMenu(MenuRequest request)
        {
            var obj = new Menu
            {
                Id           = Guid.NewGuid(),
                CreatedTime  = DateTime.Now,
                DeletedTime  = null,
                DeletedState = 0,
                FunctionKey  = request.FunctionKey,
                FunctionName = request.FunctionName,
                FunctionType = request.FunctionType,
                FunctionUrl  = request.FunctionUrl,
                Icon         = request.Icon,
                DisplayNo    = request.DisplayNo,
                ParentID     = request.ParentID
            };

            _projectMenuRepository.PreInsert(obj);
            return(_projectMenuRepository.SaveChanges());
        }
Exemplo n.º 25
0
        /// <summary>
        /// Remove menu data
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public MenuResponse RemoveData(MenuRequest request)
        {
            MenuResponse response = new MenuResponse();

            try
            {
                var menu = _unitOfWork.MenuRepository.GetById(request.Data.Id);
                if (menu.ID > 0)
                {
                    menu.RowStatus    = -1;
                    menu.ModifiedBy   = request.Data.Account.UserCode;
                    menu.ModifiedDate = DateTime.Now;

                    _unitOfWork.MenuRepository.Update(menu);
                    int resultAffected = _unitOfWork.Save();
                    if (resultAffected > 0)
                    {
                        response.Message = string.Format(Messages.ObjectHasBeenRemoved, "Menu", menu.Name, menu.ID);
                    }
                    else
                    {
                        response.Status  = false;
                        response.Message = string.Format(Messages.RemoveObjectFailed, "Menu");
                    }
                }
                else
                {
                    response.Status  = false;
                    response.Message = string.Format(Messages.RemoveObjectFailed, "Menu");
                }
            }
            catch (Exception ex)
            {
                response.Status  = false;
                response.Message = Messages.GeneralError;

                ErrorLog(ClinicEnums.Module.MASTER_MENU, ClinicEnums.Action.DELETE.ToString(), request.Data.Account, ex);
            }

            return(response);
        }
Exemplo n.º 26
0
        private async Task GetMenus(string profile)
        {
            DependencyService.Get <IProgressInterface>().Show();

            MenuRequest menuRequest = new MenuRequest
            {
                profile = profile
            };

            var    jsonRequest = JsonConvert.SerializeObject(menuRequest);
            var    content     = new StringContent(jsonRequest, Encoding.UTF8, "text/json");
            var    response    = new Response();
            string result;

            //envio

            try
            {
                response = await ApiService.ConsumoGET(ApiService.URL, "api/User/GetMenu", new Dictionary <string, string> {
                    { "profile", "" }
                });

                result = response.Result;
            }
            catch
            {
            }

            if (response.Code >= 400)
            {
                ShowErrorMessage(response.Result);
                DependencyService.Get <IProgressInterface>().Hide();
                return;
            }
            else if (response.Code >= 200 && response.Code < 300)
            {
                MenuItemsAux = JsonConvert.DeserializeObject <List <MenuItem> >(response.Result);
                DependencyService.Get <IProgressInterface>().Hide();
                return;
            }
        }
Exemplo n.º 27
0
        public Response <int> updateMenu([FromBody] MenuRequest request)
        {
            string userlogin = string.Empty;
            string token     = Request.Headers["Authorization"];

            // Get user login from token
            var            info     = this._authService.checkToken(token);
            Response <int> response = new Response <int>();

            if (!string.IsNullOrEmpty(info.Username))
            {
                request.UserLogin = info.Username;
                return(this._authService.updateMenu(request));
            }
            else
            {
                response.message      = "Unauthorize";
                response.message_type = 2;
            }
            return(response);
        }
Exemplo n.º 28
0
 /// <summary>
 /// Runs the handle methods depending on what the user requested.
 /// </summary>
 /// <param name="req">The user request</param>
 internal static void HandleRequest(MenuRequest req)
 {
     Log.Information("Determining which request to handle");
     if (req.Equals(MenuRequest.PlaceOrder))
     {
         HandleRequestPlaceOrder();
     }
     else if (req.Equals(MenuRequest.AddCustomer))
     {
         HandleRequestAddCustomer();
     }
     else if (req.Equals(MenuRequest.SearchCustomer))
     {
         HandleRequestSearchCustomer();
     }
     else if (req.Equals(MenuRequest.DisplayDetailsOfOrder))
     {
         HandleRequestDisplayDetailsOfOrder();
     }
     else if (req.Equals(MenuRequest.DisplayOrderHistoryOfLocation))
     {
         HandleRequestDisplayOrderHistoryOfLocation();
     }
     else if (req.Equals(MenuRequest.DisplayOrderHistoryOfCustomer))
     {
         HandleRequestDisplayOrderHistoryOfCustomer();
     }
     else if (req.Equals(MenuRequest.DisplayAllLocations))
     {
         HandleRequestDisplayAllLocations();
     }
     else if (req.Equals(MenuRequest.Exit))
     {
         HandleRequestExit();
     }
     else
     {
         HandleRequestInvalid();
     }
 }
Exemplo n.º 29
0
        private async Task GetMenus(string profile)
        {
            ShowLoading();

            MenuRequest menuRequest = new MenuRequest
            {
                profile = profile
            };

            var    jsonRequest = JsonConvert.SerializeObject(menuRequest);
            var    content     = new StringContent(jsonRequest, Encoding.UTF8, "text/json");
            var    response    = new Response();
            string result;

            //envio

            try
            {
                response = await ApiService.ConsumoPOST(ApiService.URL, "api_appsiif/api/User/GetMenu", content);

                result = response.Result;
            }
            catch
            {
            }

            if (response.Code >= 400)
            {
                ShowErrorMessage(response.Result);
                HideLoading();
                return;
            }
            else if (response.Code >= 200 && response.Code < 300)
            {
                MenuItemsAux = JsonConvert.DeserializeObject <List <MenuItem> >(response.Result);
                HideLoading();
                return;
            }
        }
Exemplo n.º 30
0
        public async Task <IActionResult> PostMenu([FromBody] MenuRequest request)
        {
            MenuResponse response;

            if (ModelState.IsValid)
            {
                response = await _menuService.CreateAsync(request);

                var url = Url.Link("GetMenuById", new { id = response.MenuId });
                return(Created(url, new ApiResponse
                {
                    Status = true,
                    Message = "Success",
                    Result = url
                }));
            }
            return(BadRequest(
                       new ApiResponse
            {
                Status = false,
                Message = "Validation Failure"
            }));
        }