Exemple #1
0
        public void UpdateMenuItem(MenuItemDto updatedItem)
        {
            var itemToUpdate = _unitOfWork.MenuItems.Get(updatedItem.Id);

            if (itemToUpdate == null)
            {
                throw new ObjectNotFoundException
                      {
                          Title   = "Ошибка при попытке редактирования объекта",
                          Message = "Объект не найден."
                      };
            }

            itemToUpdate.LastEdited = DateTime.Now;
            itemToUpdate.Name       = updatedItem.Name;
            itemToUpdate.Amount     = updatedItem.Amount;
            itemToUpdate.Price      = updatedItem.Price;

            itemToUpdate.Categories.Clear();
            updatedItem.Categories.ToList()
            .ForEach(c =>
            {
                itemToUpdate.Categories.Add(_unitOfWork.Categories.Get(c.Id));
            });

            _unitOfWork.MenuItems.Update(itemToUpdate);
            _unitOfWork.Save();
        }
Exemple #2
0
        public async Task <MenuItemDto> PutMenuItem(int id, MenuItemDto model)
        {
            var url    = CRMApiUri + "/MenuItem/" + id;
            var result = await PutRequestToApi(url, model);

            return(result);
        }
Exemple #3
0
 public MenuListItem(MenuItemDto menuItemDto)
 {
     MenuItemId = menuItemDto.Id;
     ItemName   = menuItemDto.Name;
     Category   = menuItemDto.Category;
     Price      = menuItemDto.Price;
 }
Exemple #4
0
        public ResponseModel <MenuItemDto> SaveMenuItem(MenuItemDto item)
        {
            ResponseModel <MenuItemDto> response = new ResponseModel <MenuItemDto>();

            try
            {
                var entity = Mapper <MenuItemDto, MenuItem> .Map(item, new MenuItem());

                if (entity.Id > 0)
                {
                    _unitOfWork.Repository <MenuItem>().Insert(entity);
                }
                else
                {
                    _unitOfWork.Repository <MenuItem>().Insert(entity);
                }
                _unitOfWork.Save();
                item.Id                 = entity.Id;
                response.IsSuccess      = true;
                response.SuccessCode    = CommonConstants.SuccessCode.MenuItemSaved;
                response.ResponseObject = item;
            }
            catch (Exception ex)
            {
                response.IsFailed  = true;
                response.ErrorCode = CommonConstants.ErrorCode.InternalServerError;
            }
            return(response);
        }
Exemple #5
0
        public virtual List <MenuItemDto> GetUserMenuItems(string userId)
        {
            using (var db = GetDbContext())
            {
                var tsUser = db.GetTable <TsUser>()
                             .FirstOrDefault(x => x.Id.Equals(userId));

                var result = new List <MenuItemDto>();
                if (tsUser.CUserType == 9)
                {
                    result = db.GetTable <TsResource>()
                             .Where(x => x.CType.Equals(2))
                             .Select(x => MenuItemDto.Map(x))
                             .ToList();
                }
                else
                {
                    var roles       = GetUserRoles(userId);
                    var resourceIds = db.GetTable <TsRolePermission>()
                                      .Where(x => roles.Contains(x.CRoleId) && (x.CResourceType.Equals(2) || x.CResourceType.Equals(64)))
                                      .Select(x => x.CResourceId)
                                      .ToList();
                    result = db.GetTable <TsResource>()
                             .Where(x => resourceIds.Contains(x.Id))
                             .OrderBy(x => x.COrder)
                             .Select(x => MenuItemDto.Map(x))
                             .ToList();
                }
                return(result);
            }
        }
Exemple #6
0
        public async Task <JsonResult> AddNewItem([FromBody] InputMenuItemModel inputMenuItemModel)
        {
            if (inputMenuItemModel.Name.IsNullOrWhiteSpace())
            {
                return(AjaxHelper.JsonResult(HttpStatusCode.BadRequest, "菜单项名不能为空"));
            }
            string token       = HttpContext.Request.Headers["token"];
            var    userId      = (await LoginManager.GetUserIdAsync(token)).GetValueOrDefault();
            var    menuItemDto = new MenuItemDto
            {
                Name                   = inputMenuItemModel.Name,
                Url                    = inputMenuItemModel.Url,
                CustomData             = inputMenuItemModel.CustomData,
                Icon                   = inputMenuItemModel.Icon,
                ClassName              = inputMenuItemModel.ClassName,
                OrderIn                = inputMenuItemModel.OrderIn,
                RequiredPermissionName = inputMenuItemModel.RequiredPermissionName,
                RequiresAuthentication = inputMenuItemModel.RequiresAuthentication,
                MenuItems              = inputMenuItemModel.MenuItems.Select(i => new MenuItemDto
                {
                    Name                   = i.Name,
                    Url                    = i.Url,
                    CustomData             = i.CustomData,
                    Icon                   = i.Icon,
                    ClassName              = i.ClassName,
                    OrderIn                = i.OrderIn,
                    RequiredPermissionName = i.RequiredPermissionName,
                    RequiresAuthentication = i.RequiresAuthentication
                }).ToList(),
                CreatorUserId = userId
            };
            var id = await _menuItemService.InsertAndGetIdAsync(menuItemDto);

            return(AjaxHelper.JsonResult(HttpStatusCode.OK, "成功", id));
        }
Exemple #7
0
        public bool AddNew(MenuItemDto pMenuItem)
        {
            pMenuItem.id = this.GetNextId();
            Save(pMenuItem);

            return(true);
        }
Exemple #8
0
        public MenuItemDto AddNewMenuItem(MenuItemDto menuItemDto)
        {
            var menuItemToAdd = Mapper.Map <MenuItemDto, MenuItem>(menuItemDto);
            var newMenuItem   = _menuItemDataProvider.AddNewMenuItem(menuItemToAdd);

            return(Mapper.Map <MenuItem, MenuItemDto>(newMenuItem));
        }
Exemple #9
0
        public async Task <MenuItemDto> UpdateMenuItemAsync(MenuItemDto menuItemDto)
        {
            MenuItem menuItem = menuItemDto.ToEntity();
            MenuItem updated  = await _repository.UpdateMenuItemAsync(menuItem);

            return(new MenuItemDto(updated));
        }
Exemple #10
0
        public MenuItemDto UpdateMenuItem(MenuItemDto menuItemDto)
        {
            var menuItemToUpdate = Mapper.Map <MenuItemDto, MenuItem>(menuItemDto);
            var updatedMenuItem  = _menuItemDataProvider.UpdateMenuItem(menuItemToUpdate);

            return(Mapper.Map <MenuItem, MenuItemDto>(updatedMenuItem));
        }
        public int UpsertMenuItem(MenuItemDto menuItemDto)
        {
            var menuItem = new MenuItem
            {
                MenuItemId         = menuItemDto.MenuItemId,
                Image              = menuItemDto.Image,
                MenuItemCategoryId = menuItemDto.CategoryId,
                Name         = menuItemDto.Name,
                RestaurantId = menuItemDto.RestaurantId,
                Price        = menuItemDto.Price,
            };

            if (menuItemDto.MenuItemId == 0)
            {
                _dbContext.MenuItems.Add(menuItem);
            }
            else
            {
                _dbContext.MenuItems.Update(menuItem);
            }

            _dbContext.SaveChanges();

            return(menuItem.MenuItemId);
        }
Exemple #12
0
        public async Task <BaseEntity> SaveAndReturnEntityAsync(MenuItemDto entityDto)
        {
            var entity = _mapper.Map <MenuItem>(entityDto);
            var result = await _repository.SaveAndReturnEntityAsync(entity);

            return(result);
        }
Exemple #13
0
        public async Task <MenuItemDto> PostMenuItem(MenuItemDto model)
        {
            var url    = CRMApiUri + "/MenuItem";
            var result = await PostRequestToApi(url, model);

            return(result);
        }
Exemple #14
0
        public async Task <JsonResult> GetAsync()
        {
            Dictionary <Menu, List <Menu> > menuDatas = await this._menuService.GetAllMenusAsync();

            List <MenuDto> results = new List <MenuDto>();

            foreach (KeyValuePair <Menu, List <Menu> > item in menuDatas)
            {
                MenuDto mainMenu = new MenuDto();
                mainMenu.Title     = item.Key.Name;
                mainMenu.IconType  = item.Key.IconType;
                mainMenu.Path      = item.Key.Path;
                mainMenu.MenuItems = new List <MenuItemDto>();
                foreach (Menu valueItem in item.Value)
                {
                    MenuItemDto menuItem = new MenuItemDto();
                    menuItem.Title = valueItem.Name;
                    menuItem.Path  = valueItem.Path;
                    mainMenu.MenuItems.Add(menuItem);
                }
                results.Add(mainMenu);
            }

            return(new JsonResult(results));
            //return new JsonResult(new List<string>() { "a", "b", "c" });
        }
Exemple #15
0
 public async Task Delete(MenuItemDto menuItem)
 {
     using (UnitOfWorkProvider.Create())
     {
         _menuItemService.DeleteProduct(menuItem.Id);
         await UnitOfWorkProvider.GetUnitOfWorkInstance().Commit();
     }
 }
Exemple #16
0
        public IActionResult Add(int applicationId)
        {
            var model = new MenuItemDto {
                ApplicationId = applicationId
            };

            return(PartialView("Edit", model));
        }
Exemple #17
0
        public void UpdateMenuItem(MenuItemDto updatedItem)
        {
            //ExecuteWithExceptionHandling(() => _menuManager.UpdateMenuItem(updatedItem));
            var a = 1;

            ExecuteWithExceptionHandling(() => _menuManager.UpdateMenuItem(updatedItem));
            var b = 3;
        }
Exemple #18
0
        public async Task <IActionResult> Post([FromBody] MenuItemDto menuItem)
        {
            if (menuItem.Id != 0)
            {
                return(StatusCode(StatusCodes.Status400BadRequest, "Identity insert is not permitted."));
            }

            return(await SaveAndReturnEntityAsync(async() => await _menuItemService.SaveAndReturnEntityAsync(menuItem)));
        }
Exemple #19
0
        public async Task Update(MenuItemDto menuItem)
        {
            using (UnitOfWorkProvider.Create())
            {
                await _menuItemService.Update(menuItem);

                await UnitOfWorkProvider.GetUnitOfWorkInstance().Commit();
            }
        }
Exemple #20
0
        public async Task <IActionResult> Put(int id, [FromBody] MenuItemDto menuItem)
        {
            if (id == 0 || menuItem.Id == 0)
            {
                return(StatusCode(StatusCodes.Status400BadRequest, "Id needs to be greater than 0."));
            }

            return(await SaveAndReturnEntityAsync(async() => await _menuItemService.SaveAndReturnEntityAsync(menuItem)));
        }
Exemple #21
0
 /// <summary>
 /// 根据ID获取模块信息
 /// </summary>
 /// <param name="id">主键</param>
 /// <returns></returns>
 public virtual MenuItemDto GetById(string id)
 {
     using (var db = GetDbContext())
     {
         return(db.GetTable <TsResource>()
                .Select(x => MenuItemDto.Map(x))
                .FirstOrDefault(x => x.Id == id));
     }
 }
        public async Task <MenuItemDto> CreateMenuItem(MenuItemDto menuItemDto)
        {
            var menuItem = _mapper.Map <MenuItem>(menuItemDto);

            var createdMenuItem = await _menuItemRepository.Add(menuItem);

            var createdMenuItemDto = _mapper.Map <MenuItemDto>(createdMenuItem);

            return(createdMenuItemDto);
        }
Exemple #23
0
        public MenuNodeItem(MenuItemDto menuItemDto)
        {
            MenuItemId = menuItemDto.Id;
            ItemName   = menuItemDto.Name;
            Price      = menuItemDto.Price;
            Category   = menuItemDto.Category;
            Extra      = menuItemDto.Extra;

            Text = menuItemDto.Name;
        }
Exemple #24
0
 public async Task <ActionResult <MenuItemDto> > UpdateMenuItem([FromBody] MenuItemDto menuItemDto)
 {
     try
     {
         return(Ok(await _service.UpdateMenuItemAsync(menuItemDto)));
     }
     catch (Exception e)
     {
         return(Conflict(e.Message));
     }
 }
Exemple #25
0
        public async Task <ActionResult <MenuItemDto> > Post(MenuItemDto dto)
        {
            var entity = new MenuItem();

            mapper.Map(dto, entity);
            dataContext.Add(entity);
            await dataContext.SaveChangesAsync();

            dto.Id = entity.Id;
            return(dto);
        }
Exemple #26
0
    private void AddChildItems(MenuItemDto menuItem, List <MenuItemDto> source, IHasMenuItems parent = null)
    {
        var applicationMenuItem = CreateApplicationMenuItem(menuItem);

        foreach (var item in source.Where(x => x.ParentId == menuItem.Id && x.IsActive))
        {
            AddChildItems(item, source, applicationMenuItem);
        }

        parent?.Items.Add(applicationMenuItem);
    }
        public void Delete(MenuItemDto menuItem)
        {
            MenuItem item = _agileBridgeContext.MenuItem
                            .FirstOrDefault(x => x.Id == menuItem.Id);

            if (item != null)
            {
                _agileBridgeContext.MenuItem.Remove(item);
                _agileBridgeContext.SaveChanges();
            }
        }
Exemple #28
0
        public async Task <MenuItemDto> CreateMenuItemAsync(MenuItemDto menuItemDto)
        {
            MenuItem menuItem = menuItemDto.ToEntity();
            MenuItem created  = await _repository.AddMenuItemAsync(menuItem);

            if (created == null)
            {
                throw new Exception("Category doea not exist.");
            }
            return(new MenuItemDto(created));
        }
Exemple #29
0
        public int AddMenuItem(MenuItemDto menuItem)
        {
            var newItem = Mapper.Map <MenuItemDto, MenuItem>(menuItem);

            newItem.Created    = DateTime.Now;
            newItem.LastEdited = DateTime.Now;

            _unitOfWork.MenuItems.Add(newItem);
            _unitOfWork.Save();

            return(newItem.Id);
        }
Exemple #30
0
        public async Task <ActionResult <MenuItemDto> > Put(MenuItemDto dto)
        {
            var entity = await dataContext.Set <MenuItem>().FirstOrDefaultAsync(x => x.Id == dto.Id);

            if (entity == null)
            {
                return(NotFound());
            }
            mapper.Map(dto, entity);
            await dataContext.SaveChangesAsync();

            return(dto);
        }