Example #1
0
        public async Task <IActionResult> AddNewItem(MenuForAddItemDto menuForAddItemDto)
        {
            var menuItemForAdd = mapper.Map <MenuItem>(menuForAddItemDto);

            menuRepository.Add(menuItemForAdd);

            if (await menuRepository.SaveAll())
            {
                return(Ok());
            }

            return(BadRequest("Could not add menu item."));
        }
        public ActionResult AddNew(VeChungToiModel objectMenu)
        {
            if (ModelState.IsValid)
            {
                Menu model = new Menu()
                {
                    CodeProduct = RejectMarks(objectMenu.NameProduct),


                    IdNhaCungCap = 12,
                    idControl    = 17,
                    ok           = true,
                    Link         = ConvertFont(objectMenu.NameProduct),
                    LevelMenu    = 1,
                    LinkHttp     = "https://beautygarden.vn/" + ConvertFont(objectMenu.NameProduct) + ".html",
                    Style        = "ho-tro",
                    ui           = "vi",
                    sPosition    = objectMenu.sPosition,
                    sDate        = DateTime.Now,
                    sDateOk      = DateTime.Now,
                    idUser       = 18,
                    idUserOk     = 18,
                    NameProduct  = objectMenu.NameProduct,
                    Content      = objectMenu.Content
                };
                _menuRepository.Add(model);
                _unitOfWork.Commit();
            }
            else
            {
                return(View("Create", objectMenu));
            }
            return(RedirectToAction("Index"));
        }
Example #3
0
        public async Task <IActionResult> CreateCategory(int hotelId, CategoryForUpdateDto categoryForUpdateDto)
        {
            if (categoryForUpdateDto == null)
            {
                return(BadRequest());
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var categoryEntity = _mapper.Map <Category>(categoryForUpdateDto);

            categoryEntity.HotelId = hotelId;

            _repo.Add(categoryEntity);

            if (await _unitOfWork.CompleteAsync())
            {
                var categoryToReturn = _mapper.Map <CategoryForUpdateDto>(categoryEntity);
                return(CreatedAtRoute("GetCategory", new { id = categoryEntity.Id }, categoryToReturn));
            }

            throw new Exception("Creating the category failed on save");
        }
Example #4
0
 public ActionResult AddNew(ThemBannerTrangChuModel model)
 {
     if (ModelState.IsValid)
     {
         Menu menu = new Menu()
         {
             CodeProduct  = RejectMarks(model.NameProduct),
             Img          = (model.Img).Replace("/files/", ""),
             IdNhaCungCap = 12,
             idControl    = 23,
             ok           = true,
             Link         = ConvertFont(model.NameProduct),
             LevelMenu    = 1,
             LinkHttp     = "https://beautygarden.vn/" + ConvertFont(model.NameProduct) + ".html",
             Style        = "banner-website-top-desktop",
             sPosition    = model.sPosition,
             sDate        = DateTime.Now,
             sDateOk      = DateTime.Now,
             idUser       = 18,
             idUserOk     = 18,
             NameProduct  = model.NameProduct,
             LinkHttp1    = model.LinkHttp1,
             NgayHetHang  = DateTime.Now
         };
         _menuRepository.Add(menu);
         _menuRepository.ClearCacheBannerHome(Shop.Web.Core.Cache.CacheKey.BannerHomeCacheKey);
         _unitOfWork.Commit();
     }
     else
     {
         return(View("Create", model));
     }
     return(RedirectToAction("Index"));
 }
        public async Task <IActionResult> ExecuteAsync(SaveMenu saveMenu, CancellationToken cancellationToken)
        {
            var menu = _saveMenuToMenuMapper.Map(saveMenu);

            //var user = _httpContextAccessor.HttpContext.User;
            //if (user == null)
            //    return new NotFoundResult();

            //var claims = user.Claims.ToList();
            //if (claims.Count < 1)
            //    return new NotFoundResult();

            //var userId = claims.FirstOrDefault(claimRecord => claimRecord.Type == "sub").Value;

            //if (menu.CreatedBy == null)
            //    menu.CreatedBy = userId;
            //menu.ModifiedBy = userId;


            menu = await _menuRepository.Add(menu, cancellationToken);

            var menuViewModel = _menuToMenuMapper.Map(menu);

            return(new CreatedAtRouteResult(
                       MenusControllerRoute.GetMenu,
                       new { id = menuViewModel.Id },
                       menuViewModel));
        }
Example #6
0
 public IActionResult SaveAsync(Menu_VM menu_VM)
 {
     if (menu_VM != null)
     {
         if (menu_VM.Id > 0)
         {
             if (_menuRepository.Update(menu_VM, this.loginUserId) > 0)
             {
                 TempData["Status"]  = Helper.success_code;
                 TempData["Message"] = Message.menuUpdated;
             }
             else
             {
                 TempData["Message"] = Message.menuItemUpdatedError;
             }
         }
         else
         {
             if (_menuRepository.Add(menu_VM, this.loginUserId) > 0)
             {
                 TempData["Status"]  = Helper.success_code;
                 TempData["Message"] = Message.menuAdded;
             }
             else
             {
                 TempData["Message"] = Message.menuAddedError;
             }
         }
     }
     return(RedirectToAction("List", "Menu"));
 }
        public JsonResult Addnew(int IdMenu, string NameProduct, int IPosition)
        {
            Menu menu = new Menu()
            {
                //admin/submenu1/index/1240
                idControl     = IdMenu,             //danh muc con cap 1
                VIP           = false,
                Link          = ConvertFont(NameProduct),
                Style         = "danh-muc-san-pham",
                ui            = "vi",
                IdNhaCungCap  = 12,
                Visitor       = 0,
                ok            = true,
                sDate         = DateTime.Now,
                sDateOk       = DateTime.Now,
                idUser        = 18,
                idUserOk      = 18,
                CodeProduct   = RejectMarks(NameProduct),
                NameProduct   = NameProduct,
                SapxepDanhMuc = IPosition,
                ShowMenuHome  = true,
                ShowMenuTop   = true
            };

            _menuRepository.Add(menu);
            _unitOfWork.Commit();

            return(Json(new
            {
                message = "Thêm mới thành công!"
            }, JsonRequestBehavior.AllowGet));
        }
Example #8
0
        public async Task <IActionResult> CreateExtra(int hotelId, [FromBody] ExtraForUpdateDto extraForUpdateDto)
        {
            if (extraForUpdateDto == null)
            {
                return(BadRequest());
            }

/*             if (!ModelState.IsValid)
 *              return BadRequest(ModelState); */

            // retieve the hotel id from the login user

/*             var currentUserId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);
 *
 *          var userFromRepo = await _hotelrepo.GetUser(currentUserId); */

            var extraEntity = _mapper.Map <Extra>(extraForUpdateDto);

            extraEntity.HotelId = hotelId;

            _repo.Add(extraEntity);

            if (await _unitOfWork.CompleteAsync())
            {
                var extraToReturn = _mapper.Map <ExtraForUpdateDto>(extraEntity);
                return(CreatedAtRoute("GetExtra", new { id = extraEntity.Id }, extraToReturn));
            }

            throw new Exception("Creating the option or extra failed on save");
        }
Example #9
0
        public async Task <Menu> Add(Menu model)
        {
            var entity = _menuRepository.Add(model);
            await _menuRepository.SaveChangeAsync();

            return(model);
        }
Example #10
0
        public ActionResult Action(tblMenu objSubmit)
        {
            if (objSubmit.ID == 0)
            {
                objSubmit.DateCreated = DateTime.Now;
                objSubmit.DateUpdated = DateTime.Now;
                objSubmit.CreatedBy   = User.Identity.Name;
                objSubmit.UpdatedBy   = User.Identity.Name;
                objSubmit.IsDeleted   = false;
                objSubmit.IsShow      = true;
                menuRepository.Add(objSubmit);
            }
            else
            {
                var obj = menuRepository.GetById <tblMenu>(objSubmit.ID);

                objSubmit.DateUpdated = DateTime.Now;
                objSubmit.UpdatedBy   = User.Identity.Name;

                UpdateModel(obj);

                objSubmit.DateUpdated = DateTime.Now;

                menuRepository.Update(obj);
            }

            return(Json(new
            {
                Error = false
            }, JsonRequestBehavior.AllowGet));
        }
        public async Task <ICommandResult> Handle(MenuAddCommand message)
        {
            try
            {
                Menu menu = new Menu();
                menu.Add(message);
                await _menuRepository.Add(menu);

                ICommandResult result = new CommandResult()
                {
                    Message  = "",
                    ObjectId = menu.Id,
                    Status   = CommandResult.StatusEnum.Sucess
                };
                return(result);
            }
            catch (Exception e)
            {
                e.Data["Param"] = message;
                ICommandResult result = new CommandResult()
                {
                    Message = e.Message,
                    Status  = CommandResult.StatusEnum.Fail
                };
                return(result);
            }
        }
Example #12
0
 /// <summary>
 /// Добавить меню в репозиторий
 /// </summary>
 /// <param name="menu">Меню на добавление</param>
 public void AddMenuInRepository(IMenu menu)
 {
     if (menu == null)
     {
         throw new ArgumentNullException("NewMenu");
     }
     _MenuController.Add(menu);
 }
Example #13
0
        private void InsertOrUpdateMenu(IMenuRepository menuRepository, int index, Menu menu, MenuLevel level, Guid?parentId)
        {
            // sort start with 1

            // a1, check the paramters
            //  1, check the level and parentId
            //      1a, when level = parent, the parentId = null
            //      2a, when level != parent and the parentId = null, throw exception.
            // a2, check the index
            //  1, index > 0

            // a1, when level = parent
            //  1, find all menus that level = parent
            //      1a, if the index > menus count, set the sort = (countOfMenu + 1)
            //      1b, if the index <= menus count, set the sort = (countOfMenu + 1), then set the sort that large then index add one
            // a2, when level = child
            //  1, find all menus that parentId = input parentId
            //      1a, when the index > menus count, set the sort = (countOfMenu + 1)
            //      1b, when the index <= menus count, set the sort = (countOfMenu + 1), then set the sort that large then index add one

            ISpecification <Menu> spec = null;
            var existMenu = menuRepository.Exist(Specification <Menu> .Eval(m => m.ID == menu.ID));

            if (level == MenuLevel.Parent)
            {
                spec = Specification <Menu> .Eval(m => m.Level == MenuLevel.Parent);
            }

            if (level == MenuLevel.Children)
            {
                if (!parentId.HasValue)
                {
                    throw new ArgumentNullException("parentId", "When menuLevel is children, the parentId must be not null.");
                }

                spec = Specification <Menu> .Eval(m => m.Level == MenuLevel.Children && m.ParentId == parentId);
            }

            var menus = this.GetMenus(menuRepository, spec, menu.ID, existMenu);

            // if the menu not exist, add the menu (the menu has been atteched).
            if (!existMenu)
            {
                var sort = this.InsertSortMenu(menus, index);
                menu.SetSort(sort);
                menuRepository.Add(menu);
            }
            else
            {
                var sort = this.MoveSortMenu(menus, menu.Sort, index);
                menu.SetSort(sort);
                menuRepository.Update(menu);
                foreach (var item in menus)
                {
                    menuRepository.Update(item);
                }
            }
        }
        private void InsertOrUpdateMenu(IMenuRepository menuRepository, int index, Menu menu, MenuLevel level, Guid? parentId)
        {
            // sort start with 1

            // a1, check the paramters
            //  1, check the level and parentId
            //      1a, when level = parent, the parentId = null
            //      2a, when level != parent and the parentId = null, throw exception.
            // a2, check the index
            //  1, index > 0

            // a1, when level = parent
            //  1, find all menus that level = parent
            //      1a, if the index > menus count, set the sort = (countOfMenu + 1)
            //      1b, if the index <= menus count, set the sort = (countOfMenu + 1), then set the sort that large then index add one
            // a2, when level = child
            //  1, find all menus that parentId = input parentId
            //      1a, when the index > menus count, set the sort = (countOfMenu + 1)
            //      1b, when the index <= menus count, set the sort = (countOfMenu + 1), then set the sort that large then index add one

            ISpecification<Menu> spec = null;
            var existMenu = menuRepository.Exist(Specification<Menu>.Eval(m => m.ID == menu.ID));

            if (level == MenuLevel.Parent)
            {
                spec = Specification<Menu>.Eval(m => m.Level == MenuLevel.Parent);
            }

            if (level == MenuLevel.Children)
            {
                if (!parentId.HasValue)
                    throw new ArgumentNullException("parentId", "When menuLevel is children, the parentId must be not null.");

                spec = Specification<Menu>.Eval(m => m.Level == MenuLevel.Children && m.ParentId == parentId);
            }

            var menus = this.GetMenus(menuRepository, spec, menu.ID, existMenu);
            
            // if the menu not exist, add the menu (the menu has been atteched).
            if (!existMenu)
            {
                var sort = this.InsertSortMenu(menus, index);
                menu.SetSort(sort);
                menuRepository.Add(menu);
            }
            else
            {
                var sort = this.MoveSortMenu(menus, menu.Sort, index);
                menu.SetSort(sort);
                menuRepository.Update(menu);
                foreach (var item in menus)
                    menuRepository.Update(item);
            }
        }
Example #15
0
        public async Task <IActionResult> CreateOrder(MenuOrderCreateDto menuOrderCreateDto)
        {
            if (menuOrderCreateDto == null)
            {
                return(BadRequest());
            }

            var currentUserId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);

            // booking details
            var bookingFromRepo = await _bookingrepo.GuestCurrentBooking(currentUserId);

            if (bookingFromRepo == null)
            {
                return(NotFound($"Could not find guest booking"));
            }

            var menuOrderEntity = _mapper.Map <MenuOrder>(menuOrderCreateDto);

            menuOrderEntity.GuestName   = bookingFromRepo.GuestName;
            menuOrderEntity.Email       = bookingFromRepo.Email;
            menuOrderEntity.Phone       = bookingFromRepo.Phone;
            menuOrderEntity.RoomNumber  = bookingFromRepo.RoomNumber;
            menuOrderEntity.OrderStatus = "Pending";
            menuOrderEntity.IsDeleted   = false;
            menuOrderEntity.BookingId   = bookingFromRepo.Id;
            menuOrderEntity.HotelId     = bookingFromRepo.HotelId;
            _repo.Add(menuOrderEntity);

            /// signalR section to copy out
            var notificationFromRepo = await _hotelrepo.GetNotificationCounters(bookingFromRepo.HotelId);

            if (notificationFromRepo != null)
            {
                notificationFromRepo.OrderCount += 1;

                var notificationToReturn = _mapper.Map <NotificationDto>(notificationFromRepo);

                var notificationMessage = NotificationMessage.CreateNotification(bookingFromRepo.HotelId, "Order",
                                                                                 menuOrderEntity.RoomNumber, notificationToReturn);

                await _notifyHub.Clients.All.SendAsync("NewRequest", notificationMessage);
            }

            if (await _unitOfWork.CompleteAsync())
            {
                var MenuOrderToReturn = _mapper.Map <MenuOrderUpdateDto>(menuOrderEntity);

                return(CreatedAtRoute("GetMenuOrder", new { id = MenuOrderToReturn.Id }, MenuOrderToReturn));
            }

            throw new Exception("Creating the taxi failed on save");
        }
Example #16
0
        public int AddMenu(AddMenuViewModel addMenu)
        {
            Menu menu = new Menu
            {
                MenuName = addMenu.MenuName,
            };

            _menuRepository.Add(menu);
            _menuRepository.SaveChanges();

            return(menu.Id);
        }
        public Menu AddMenu(Menu menu)
        {
            Condition.WithExceptionOnFailure <InvalidParameterException>()
            .Requires(menu, "menu")
            .IsNotNull();

            var resultAdd = _menuRepository.Add(menu);

            _menuRepository.Save();
            return(menu);

            // return _menuRepository.Add(menu);
        }
        public async Task <IActionResult> Create([FromBody] Menu menu)
        {
            menu.DishIds = new HashSet <string>(menu.DishIds);
            _menuRepository.Add(menu);

            var testMenu = await _menuRepository.GetById(menu.Id);

            await _unitOfWork.Commit();

            testMenu = await _menuRepository.GetById(menu.Id);

            return(Ok(testMenu));
        }
 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();
     }
 }
        public ActionResult Addnew(ThemDanhMucModel model)
        {
            #region thêm danh mục sản phẩm
            if (ModelState.IsValid)
            {
                Menu menu = new Menu()
                {
                    idControl      = 1,//danh muc cha
                    Link           = ConvertFont(model.NameProduct),
                    LevelMenu      = 1,
                    Img            = (model.Img).Replace("/files/", ""),
                    Style          = "danh-muc-san-pham",
                    ui             = "vi",
                    IdNhaCungCap   = 12,
                    Visitor        = 0,
                    ok             = true,
                    sDate          = DateTime.Now,
                    sDateOk        = DateTime.Now,
                    idUser         = 18,
                    idUserOk       = 18,
                    CodeProduct    = RejectMarks(model.NameProduct),
                    NameProduct    = model.NameProduct,
                    IconMenu       = (model.IconMenu).Replace("/files/", ""),
                    ShowMenuHome   = model.ShowMenuHome,
                    ShowMenuTop    = model.ShowMenuTop,
                    SapxepDanhMuc  = model.SapxepDanhMuc,
                    BannerDanhMuc  = (model.BannerDanhMuc).Replace("/files/", ""),
                    MoTaDanhMuc    = model.MoTaDanhMuc,
                    GiaThiTruong   = 0,
                    SEODescription = model.SEODescription,
                    SEOtitle       = model.SEOtitle
                };
                _menuRepository.Add(menu);

                _menuRepository.ClearCacheByKey(new List <string>()
                {
                    Shop.Web.Core.Cache.CacheKey.AllMenu
                });
                _unitOfWork.Commit();
            }
            else
            {
                ViewData["thongbao"] = "Vui lòng nhập đầy đủ dữ liệu!";
                return(View("Create", model));
            }

            return(RedirectToAction("ViewDanhMuc"));

            #endregion
        }
Example #21
0
        public InsertDataMenuResponse InsertDataMenu(InsertDataMenuRequest request)
        {
            InsertDataMenuResponse response = new InsertDataMenuResponse();

            try
            {
                _menuRepo.Add(request.Menu);
            }
            catch (Exception ex)
            {
                response.Messages.Add(ex.ToString());
            }

            return(response);
        }
Example #22
0
        public void Adicionar(MenuModel menu)
        {
            if (!ValidMenu(menu))
            {
                return;
            }
            if (!ChecarMenuExistente(menu, "2"))
            {
                return;
            }

            _menuRepo.Add(menu);

            Commit();
        }
Example #23
0
        public void Create(MenuViewModel model)
        {
            Menu create = new Menu()
            {
                Text         = model.Text,
                Link         = model.Link,
                DisplayOrder = model.DisplayOrder,
                Status       = true,
                MenuTypeId   = model.MenuTypeId,
                Image        = model.Image
            };

            menuRepository.Add(create);
            menuRepository.Save();
        }
Example #24
0
 public ActionResult AddMainMenu(Menu menu)
 {
     try
     {
         if (menu != null)
         {
             menu.FMenuID = 0;
             Menu addMenu = MenuRepository.Add(menu);
             if (addMenu != null)
             {
                 return(Json(new
                 {
                     Success = true,
                     Msg = "主菜单添加成功。"
                 }));
             }
         }
         return(Json(new
         {
             Success = false,
             Msg = "添加失败,请重新提交。"
         }));
     }
     catch (Exception ex)
     {
         LogRepository.Add(new EventLog()
         {
             Name = Session["LoginedUser"].ToString(), Date = DateTime.Now.ToLocalTime(), Event = "添加主菜单失败" + ex.Message
         });
         return(Json(new
         {
             Success = false,
             Msg = "添加失败," + ex.Message
         }));
     }
 }
Example #25
0
        public async Task <MenuDto> AddAsync(MenuDto dto)
        {
            try
            {
                using (var dbContext = _dbContextScopeFactory.Create())
                {
                    var entity = Menu.Create(dto);
                    _menuRepository.Add(entity);
                    await dbContext.SaveChangesAsync();

                    return(_mapper.Map <MenuDto>(entity));
                }
            }
            catch (Exception ex) { }
            return(null);
        }
        public IActionResult AddSubMenu([FromBody] AddMenuVModel model)
        {
            var result = new ResultModel();

            return(this.Wrapper(ref result, () =>
            {
                result = _subMenuRepository.Add(new HeyTom.Manage.Model.Menu()
                {
                    FileName = model.fileName,
                    Name = model.name,
                    ParentId = model.parentId,
                    Path = model.path,
                    Title = model.title,
                    Icon = model.icon
                });
            }, true));
        }
Example #27
0
        /// <summary>
        /// 新增菜单
        /// </summary>
        /// <param name="requestModel">参数</param>
        /// <returns></returns>
        public ApiResultModel <int> Add(AddMenuRequestModel requestModel)
        {
            var result = new ApiResultModel <int>();

            if (requestModel.MenuName.IsNullOrEmpty())
            {
                result.Message = "菜单名称不能为空";
                return(result);
            }
            if (requestModel.ParentId.IsNullOrEmpty())
            {
                result.Message = "上级不能为空";
                return(result);
            }
            //if (requestModel.Path.IsNullOrEmpty())
            //{
            //    result.Message = "菜单路径不能为空";
            //    return result;
            //}
            if (requestModel.Type == MenuTypeEnum.Module || requestModel.Type == MenuTypeEnum.Function)
            {
                var menu = _menuRepository.FirstOrDefault(x => x.name == requestModel.MenuName && x.type == (int)requestModel.Type);
                if (menu != null)
                {
                    result.Message = "此菜单名已存在";
                    return(result);
                }
            }
            var item = new Menu()
            {
                id       = GuidTool.GetGuid(),
                name     = requestModel.MenuName,
                parentId = requestModel.ParentId,
                type     = (int)requestModel.Type,
                sort     = requestModel.Sort,
                path     = requestModel.Path ?? "",
                icon     = requestModel.Icon ?? "",
            };

            _menuRepository.Add(item);
            //_menuRepository.Entry(item).State = EntityState.Added;
            _menuRepository.SaveChanges();

            result.Code = ApiResultCode.Success;
            return(result);
        }
Example #28
0
        public AjaxResult Save(Menu menu)
        {
            bool addFlag = menu.ID < 1;
            var  user    = log.User;

            menu.CREATEBY   = user.ACCOUNT;
            menu.CREATEDATE = DateTime.Now;
            menu.UPDATEBY   = user.ACCOUNT;
            menu.UPDATEDATE = DateTime.Now;
            menu.ENABLED    = true;

            if (addFlag)
            {
                bool flag = menuRep.Add(menu);
                if (flag)
                {
                    RemoveAuthListCache();
                }
                return(new AjaxResult(flag, flag ? "菜单添加成功" : "菜单添加失败"));
            }
            else
            {
                bool flag = menuRep.Update(menu, m => new
                {
                    m.NAME,
                    m.CLASSNAME,
                    m.CODE,
                    m.IMG,
                    m.TARGET,
                    m.TITLE,
                    m.TYPE,
                    m.URL,
                    m.REMARK,
                    m.SORTID,
                    m.UPDATEBY,
                    m.UPDATEDATE,
                    m.PARENTID,
                    m.DISPLAY
                }, m => m.ID == menu.ID);
                if (flag)
                {
                    RemoveAuthListCache();
                }
                return(new AjaxResult(flag, flag ? "菜单修改成功" : "菜单修改失败"));
            }
        }
Example #29
0
        public Menu Add(Menu _model, string _userName)
        {
            return(_Repository.Add(_model));

            try
            {
                LogAction entity = new LogAction();
                entity.action     = "Thêm danh mục: <a href=\"" + _model.menuLink + "\" target=\"_blank\">" + _model.menuName + "</a>";
                entity.browser    = "";
                entity.ipAddress  = "";
                entity.userAction = _userName;
                entity.createTime = DateTime.Now;
                _RepositoryLogAction.Add(entity);
            }
            catch
            {
            }
        }
Example #30
0
        public MenuDTO Add(MenuDTO menuDTO)
        {
            var menu = menuDTO.ToModel();

            menu.Id      = IdentityGenerator.NewSequentialGuid();
            menu.Created = DateTime.UtcNow;
            if (menu.Name.IsNullOrBlank())
            {
                throw new DataExistsException(UserSystemResource.Common_Name_Empty);
            }
            if (_Repository.Exists(menu))
            {
                throw new DataExistsException(UserSystemResource.Menu_Exists);
            }
            _Repository.Add(menu);
            //commit the unit of work
            _Repository.UnitOfWork.Commit();
            return(menu.ToDto());
        }
Example #31
0
        /// <summary>
        /// 创建菜单
        /// </summary>
        /// <param name="name"></param>
        /// <param name="markedCode"></param>
        /// <param name="orderIndex"></param>
        /// <param name="parentId"></param>
        /// <param name="behavior"></param>
        public static Menu Create(string name,
                                  string markedCode,
                                  int orderIndex,
                                  Guid parentId,
                                  MenuBehavior behavior)
        {
            Menu menu = new Menu(Guid.NewGuid());

            menu.Name     = name;
            menu.Behavior = behavior;

            var node = TreeService.CreateNode(TreeGroupName, menu, parentId, orderIndex);

            IMenuRepository repository = Repository.Create <IMenuRepository>();

            repository.Add(menu);

            return(menu);
        }