public IActionResult Edit(MenuEditViewModel model) { using (_dbContext) { var entity = _dbContext.DncMenu.FirstOrDefault(x => x.Guid == model.Guid); entity.Name = model.Name; entity.Icon = string.IsNullOrEmpty(model.Icon) ? "md-menu" : model.Icon; entity.Level = 1; entity.ParentGuid = model.ParentGuid; entity.Sort = model.Sort; entity.Url = model.Url; entity.ModifiedByUserGuid = AuthContextService.CurrentUser.Guid; entity.ModifiedByUserName = AuthContextService.CurrentUser.DisplayName; entity.ModifiedOn = DateTime.Now; entity.Description = model.Description; entity.ParentName = model.ParentName; entity.Component = model.Component; entity.HideInMenu = model.HideInMenu; entity.NotCache = model.NotCache; entity.BeforeCloseFun = model.BeforeCloseFun; if (!ConfigurationManager.AppSettings.IsTrialVersion) { entity.Alias = model.Alias; entity.IsDeleted = model.IsDeleted; entity.Status = model.Status; entity.IsDefaultRouter = model.IsDefaultRouter; } _dbContext.SaveChanges(); var response = ResponseModelFactory.CreateInstance; response.SetSuccess(); return(Ok(response)); } }
public async Task <IActionResult> Create(MenuEditViewModel model) { try { if (!ModelState.IsValid) { return(BadRequest("Invalid ModelState")); } var request = new CreateMenuRequest { DisplayOrder = model.DisplayOrder, Icon = model.Icon, Title = model.Title, Url = model.Url, IsOpenInNewTab = model.IsOpenInNewTab }; var response = await _menuService.CreateAsync(request); return(Json(response)); } catch (Exception e) { Logger.LogError(e, "Error Create Nav Menu."); ModelState.AddModelError("", e.Message); return(ServerError(e.Message)); } }
public async Task <IActionResult> Edit(Guid id) { if (id == Guid.Empty) { return(NotFound()); } var menu = await _menuService.GetAsync(id); if (null == menu) { return(NotFound()); } var model = new MenuEditViewModel { Id = menu.Id, DisplayOrder = menu.DisplayOrder, Icon = menu.Icon, Title = menu.Title, Url = menu.Url, IsOpenInNewTab = menu.IsOpenInNewTab }; return(Ok(model)); }
public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } var menu = await repository.GetMenuAsync(id.Value); if (menu == null) { return(NotFound()); } var menuEditViewModel = new MenuEditViewModel { Id = menu.Id, Name = menu.Name, Description = menu.Description, Category = menu.Category, Price = menu.Price, Available = menu.Available, Special = menu.Special, SpecialPrice = menu.SpecialPrice, Image = menu.Image }; return(View(menuEditViewModel)); }
public IActionResult Edit(MenuEditViewModel model) { using (_dbContext) { var entity = _dbContext.DncMenu.FirstOrDefault(x => x.Guid == model.Guid); entity.Name = model.Name; entity.Icon = model.Icon; entity.Level = 1; entity.ParentGuid = model.ParentGuid; entity.Sort = model.Sort; entity.Url = model.Url; entity.Alias = model.Alias; entity.IsDeleted = model.IsDeleted; entity.ModifiedByUserId = 0; entity.ModifiedByUserName = ""; entity.ModifiedOn = DateTime.Now; entity.Status = model.Status; entity.Description = model.Description; entity.ParentName = model.ParentName; entity.IsDefaultRouter = model.IsDefaultRouter; _dbContext.SaveChanges(); var response = ResponseModelFactory.CreateInstance; response.SetSuccess(); return(Ok(response)); } }
public IHttpActionResult Edit(MenuEditViewModel model) { using (_dbContext) { var entity = _dbContext.Menus.FirstOrDefault(x => x.MenuId == model.MenuId); entity.Name = model.Name; entity.Icon = model.Icon; entity.Level = 1; entity.ParentId = model.ParentId; entity.Sort = model.Sort; entity.Url = model.Url; //todo 添加方便的获取用户id方法 entity.ModifiedByUserId = 1; entity.ModifiedByUserName = "******"; entity.ModifiedOn = DateTime.Now; entity.Description = model.Description; entity.ParentName = model.ParentName; entity.Component = model.Component; entity.HideInMenu = model.HideInMenu; entity.NotCache = model.NotCache; entity.BeforeCloseFun = model.BeforeCloseFun; entity.Alias = model.Alias; entity.IsDeleted = model.IsDeleted; entity.Status = model.Status; entity.IsDefaultRouter = model.IsDefaultRouter; _dbContext.SaveChanges(); var response = ResponseModelFactory.CreateInstance; response.SetSuccess(); return(Ok(response)); } }
public async Task <IActionResult> Edit([NotEmpty] Guid id) { var menu = await _menuService.GetAsync(id); if (null == menu) { return(NotFound()); } var model = new MenuEditViewModel { Id = menu.Id, DisplayOrder = menu.DisplayOrder, Icon = menu.Icon, Title = menu.Title, Url = menu.Url, IsOpenInNewTab = menu.IsOpenInNewTab, SubMenus = menu.SubMenus.Select(p => new SubMenuEditViewModel { Id = p.Id, Title = p.Title, Url = p.Url, IsOpenInNewTab = p.IsOpenInNewTab }).ToArray() }; return(Ok(model)); }
public async Task Edit_WhenCalled_UpdateMenuAndRedirectToIndex() { // Arrange repository.Setup(r => r.GetMenuAsync(1)).ReturnsAsync(menu); var model = new MenuEditViewModel { Id = 1, Name = "Double Mac Meal", Description = "Fast Food", Category = MenuCategory.Australian, Available = true, Price = 11.50m, Special = false, SpecialPrice = 0, ImageFile = null }; // Act var result = await controller.Edit(model) as RedirectToActionResult; // Assert repository.Verify(r => r.Update(menu), Times.Once); unitOfWork.Verify(u => u.CompleteAsync(), Times.Once); Assert.That(menu.Price, Is.EqualTo(11.50m)); Assert.That(menu.Name, Is.EqualTo("Double Mac Meal").IgnoreCase); Assert.That(result.ActionName, Is.EqualTo("Details").IgnoreCase); }
public async Task <IActionResult> Create(MenuEditViewModel model) { var request = new UpdateMenuRequest { DisplayOrder = model.DisplayOrder.GetValueOrDefault(), Icon = model.Icon, Title = model.Title, Url = model.Url, IsOpenInNewTab = model.IsOpenInNewTab }; if (null != model.SubMenus) { var subMenuRequests = model.SubMenus .Select(p => new UpdateSubMenuRequest { Title = p.Title, Url = p.Url, IsOpenInNewTab = p.IsOpenInNewTab }).ToArray(); request.SubMenus = subMenuRequests; } var response = await _menuService.CreateAsync(request); return(Ok(response)); }
public IActionResult Edit(int id, MenuEditViewModel model) { if (id != model.ID) { return(NotFound()); } if (ModelState.IsValid) { try { Menu menu = new Menu { ID = model.ID, Naam = model.Name, OwnerID = model.OwnerID }; _menuManager.EditMenu(menu); } catch (DbUpdateConcurrencyException) { if (!MenuExists(model.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(model)); }
public IActionResult Edit(int?id) { if (id == null) { return(NotFound()); } var menu = _menuManager.GetMenu(id.Value); if (menu == null) { return(NotFound()); } List <MenuItem> menuItems = _menuItemManager.GetMenuItems(menu.ID).Data; MenuEditViewModel vm = new MenuEditViewModel { ID = menu.ID, Name = menu.Naam, Email = menu.Owner.Email, MenuItems = menuItems, Items = _itemManager.GetItems(menuItems, menu.OwnerID).Data, OwnerID = menu.OwnerID }; return(View(vm)); }
public ActionResult Create(MenuEditViewModel collection) { if (!ModelState.IsValid) { string errorMessage = string.Join("; ", ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage)); ModelState.AddModelError("", errorMessage); ViewBag.alertBox = new BootstrapAlertBox(AlertType.Error, errorMessage); return(View(collection)); } UnitOfWork uow = new UnitOfWork(); string auditGUID = Guid.NewGuid().ToString(); //check if LoginID is already taken var duplicateMenu = uow.MenuRepository.GetRecordsByFilter(c => c.StatusFlag.Equals(StatusConstant.Active) && c.MenuName.ToUpper().Equals(collection.MenuName.ToUpper())).SingleOrDefault(); if (duplicateMenu == null) { var parentModel = uow.MenuRepository.GetRecordsByFilter(c => c.StatusFlag.Equals(StatusConstant.Active) && c.MenuUID == collection.ParentMenuUID).SingleOrDefault(); var Menu = new JVK.Domain.DBModels.Menu(); Menu.MenuUID = Guid.NewGuid().ToString(); Menu.MenuName = collection.MenuName; Menu.MenuDescription = collection.MenuDescription; Menu.MenuURL = collection.MenuURL; Menu.ParentMenuUID = collection.ParentMenuUID; Menu.OrderNumber = collection.OrderNumber; if (parentModel != null) { Menu.HLevel = parentModel.HLevel + 1; } else { Menu.HLevel = 0; } Menu.StatusFlag = StatusConstant.Active; Menu.ModifiedBy = jvkUserPrivateData.userUID; Menu.ModifiedDate = DateTime.Now; Menu.AuditGUID = auditGUID; uow.MenuRepository.AddRecord(Menu); uow.SaveDBChanges(); TempData["alertBox"] = new BootstrapAlertBox(AlertType.Success, "Menu is successfully added."); return(RedirectToAction("Index")); } else { ViewBag.alertBox = new BootstrapAlertBox(AlertType.Warning, "Menu Name is already taken. Please try another name."); return(View(collection)); } }
public async Task <IActionResult> Edit(MenuEditViewModel model) { var request = new UpdateMenuRequest { Title = model.Title, DisplayOrder = model.DisplayOrder, Icon = model.Icon, Url = model.Url, IsOpenInNewTab = model.IsOpenInNewTab }; await _menuService.UpdateAsync(model.Id, request); return(Ok()); }
public async Task <IActionResult> Create(MenuEditViewModel model) { var request = new UpdateMenuRequest { DisplayOrder = model.DisplayOrder, Icon = model.Icon, Title = model.Title, Url = model.Url, IsOpenInNewTab = model.IsOpenInNewTab }; var response = await _menuService.CreateAsync(request); return(Ok(response)); }
public async Task <IActionResult> Edit(MenuEditViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var request = new EditMenuRequest(model.Id) { Title = model.Title, DisplayOrder = model.DisplayOrder, Icon = model.Icon, Url = model.Url, IsOpenInNewTab = model.IsOpenInNewTab }; await _menuService.UpdateAsync(request); return(Ok()); }
public async Task <IActionResult> Edit(MenuEditViewModel model) { try { if (ModelState.IsValid) { var menu = await repository.GetMenuAsync(model.Id); menu.Name = model.Name; menu.Description = model.Description; menu.Category = model.Category; menu.Price = model.Price; menu.Available = model.Available; menu.Special = model.Special; menu.SpecialPrice = model.SpecialPrice; menu.DateUpdated = DateTime.Now; if (model.ImageFile != null) { if (model.Image != null) { // delete the file in S3 Bucket await funcs.DeleteObjectInS3Async(model.Image); // delete the file in images folder funcs.DeleteFile(Path.Combine(uploadDirectory, model.Image)); } // upload a new image string fileName = await funcs.UploadFileAsync(model.ImageFile, uploadDirectory); if (!string.IsNullOrEmpty(fileName)) { menu.Image = fileName; // upload the new file to S3 await funcs.UploadFileToS3Async(uploadDirectory, fileName); } } repository.Update(menu); await unitOfWork.CompleteAsync(); // Invoke PUT Api function // Update normal price to special price before calling Api cause only price column in DynamoDB if (menu.Special) { menu.Price = menu.SpecialPrice; } await funcs.PutMenuToAWSAsync(menu); return(RedirectToAction(nameof(Details), new { id = menu.Id })); } return(View(model)); } catch (Exception ex) { // need to implement logging throw new Exception(ex.Message); } }