private SelectList PopCategoryDDL() { CategoryServices cgs = new CategoryServices(); var list = cgs.GetAll().ToList(); return(new SelectList(list, "id", "name")); }
public ActionResult Create(Category category) { CategoryServices services = new CategoryServices(); services.CreateCategory(category); return(RedirectToAction("Index")); }
public void AddCatagory(object parameter) { string category_name; TextBox tb = (TextBox)parameter; category_name = tb.Text; if (category_name != "") { List <category> temp_list = CategoryServices.GetAllCategoryByName(category_name.Trim()); if (temp_list.Count == 0) { category ct = new category(); ct.id = 0; ct.category_name = category_name; int temp_Category_id = CategoryServices.AddUpdateCategory(ct); if (temp_Category_id != 0) { InventoryHelper.SuccessAlert("Success", "Category " + category_name + " is Created"); // MessageBox.Show("Category " + category_name + " is Created"); BindGrid(); RaisedPropertyChanged("Category"); } } } }
public void DoAllCategoriesExist_ShouldThrowArgumentExceptionAndCorrectMessage_WhenNoSuchCategoriesInDb() { var options = TestUtils.GetOptions(nameof(DoesCategoryExist_ShouldThrowArgumentExceptionAndCorrectMessage_WhenNoSuchCategoryInDb)); using (var arrangeContext = new MovInfoContext(options)) { var mockBusinessValidator = new Mock <IBusinessLogicValidator>(); var service = new CategoryServices(arrangeContext, mockBusinessValidator.Object); var addedCategory = service.AddCategoryAsync( TestSamples.exampleCategory.Title, TestSamples.allowedRoles); arrangeContext.SaveChanges(); } using (var assertContext = new MovInfoContext(options)) { var mockWrapUserManager = new Mock <IWrapUserManager>(); var mockHttpContext = new Mock <IHttpContextAccessor>(); var categoriesIds = new long[] { 1, 2 }; var sut = new BusinessLogicValidator(mockHttpContext.Object, mockWrapUserManager.Object); var ex = Assert.ThrowsException <ArgumentException>(() => sut.DoAllCategoriesExist(assertContext, categoriesIds)); Assert.AreEqual(ex.Message, BusinessLogicValidatorMessages.OneOrMoreCategoriesMissing); } }
public CategoriesController(CategoryServices services, FilteringServices filteringServices, UserManager <User> userManager, IOptions <RoleNamesOptions> roleNamesOptions) { _services = services; _filteringServices = filteringServices; _userManager = userManager; _roleNamesOptions = roleNamesOptions.Value; }
public HttpResponseMessage UpdateCategory(int categoryID, Category category) { var updatedCategory = CategoryServices.UpdateCategory(categoryID, category); var response = Request.CreateResponse(HttpStatusCode.OK, updatedCategory, Configuration.Formatters.JsonFormatter); response.Headers.Add("API-Version", apiVersion); response.Headers.Add("Response-Type", "JSON"); response.Headers.Add("Updated-Category-URL", Request.RequestUri.AbsoluteUri); if (updatedCategory == null) { var notFoundResponse = Request.CreateResponse(HttpStatusCode.NotFound, "(404) Category Not Found", Configuration.Formatters.JsonFormatter); notFoundResponse.Headers.Add("API-Version", apiVersion); return(notFoundResponse); } else { return(response); } }
/// <summary> /// 刷新分類清單 /// </summary> private void ReloadCategory() { grid_cate.DataSource = CategoryServices.GetCateSource(); InitCateGridView(); grid_cate.ClearSelection(); grid_prod.DataSource = null; }
public SubSubCategoryController() { unitOfWork = new UnitOfWork(); SubSubCategoryServices = new SubSubCategoryServices(unitOfWork); SubCategoryServices = new SubCategoryServices(unitOfWork); CategoryServices = new CategoryServices(unitOfWork); }
public void EditCategory_Correctly() { var options = TestUtils.GetOptions(nameof(EditCategory_Correctly)); using (var arrangeContext = new MovInfoContext(options)) { var mockBusinessValidator = new Mock <IBusinessLogicValidator>(); var sut = new CategoryServices(arrangeContext, mockBusinessValidator.Object); var addedCategory = sut.AddCategoryAsync( TestSamples.exampleCategory.Title, TestSamples.allowedRoles); var editedCategory = sut.EditCategoryAsync( TestSamples.exampleCategory.Id, TestSamples.exampleCategory.Title, new List <long> { 1, 2 }, TestSamples.allowedRoles); arrangeContext.SaveChanges(); } using (var assertContext = new MovInfoContext(options)) { Assert.AreEqual(assertContext.Categories.First().Id, TestSamples.exampleCategory.Id); Assert.AreEqual(assertContext.Categories.First().Title, TestSamples.exampleCategory.Title); Assert.AreEqual(assertContext.Categories.Include(x => x.MovieCategories).First().MovieCategories.Count, 2); } }
// GET: /SysUser/Default1 public ActionResult Index(int?page, int?iden) { Pager pager = new Pager(); pager.table = "AdsCustomer"; pager.strwhere = "1=1"; int identity = iden ?? 0; if (identity != 0) { pager.strwhere = pager.strwhere + " and CustomerIdentity=" + iden; } //int roleid = rid ?? 0; //if (roleid != 0) //{ // pager.strwhere = pager.strwhere + " and CustomerRole=" + roleid; //} pager.PageSize = SkyPageSize; pager.PageNo = page ?? 1; pager.FieldKey = "CustomerId"; pager.FiledOrder = "CustomerId desc"; IList <AdsCustomer> customers = CustomerServices.GetListForPageList(pager); var customersAsIPageList = new StaticPagedList <AdsCustomer>(customers, pager.PageNo, pager.PageSize, pager.Amount); ViewBag.SmallTitle = "客户总数共计:" + pager.Amount + "人"; //CategoryServices categoryServices = new CategoryServices(); ViewData["CustomerRole"] = CategoryServices.GetCategorySelectList(SkyCustomerRootId); ViewData["CusRolebtn"] = CategoryServices.GetCategoryListByParentID(SkyCustomerRootId); return(View(customersAsIPageList)); }
public void GetCategoryMoviesCorrectly() { var options = TestUtils.GetOptions(nameof(GetCategoryMoviesCorrectly)); using (var arrangeContext = new MovInfoContext(options)) { arrangeContext.Categories.Add(TestSamples.exampleCategory); arrangeContext.Movies.Add(TestSamples.exampleMovie); TestSamples.exampleCategory.MovieCategories.Add(TestSamples.exampleMoviesCategories); arrangeContext.SaveChanges(); } using (var assertContext = new MovInfoContext(options)) { var mockBusinessValidator = new Mock <IBusinessLogicValidator>(); var sut = new CategoryServices(assertContext, mockBusinessValidator.Object); var result = sut.GetCategoryMoviesAsync(1).Result; Assert.IsInstanceOfType(result.First(), typeof(Movie)); Assert.AreEqual(result.First().Id, 1); } }
public void ShowActorInfoCorrectly() { var options = TestUtils.GetOptions(nameof(ShowActorInfoCorrectly)); using (var arrangeContext = new MovInfoContext(options)) { arrangeContext.Categories.Add(TestSamples.exampleCategory); arrangeContext.Movies.Add(TestSamples.exampleMovie); TestSamples.exampleCategory.MovieCategories.Add(TestSamples.exampleMoviesCategories); arrangeContext.SaveChanges(); } using (var assertContext = new MovInfoContext(options)) { var mockBusinessValidator = new Mock <IBusinessLogicValidator>(); var sut = new CategoryServices(assertContext, mockBusinessValidator.Object); var result = sut.ShowCategoryInfoAsync(1); Assert.AreEqual(assertContext.Categories.FirstOrDefault().Title, TestSamples.exampleCategory.Title); } }
public IActionResult Delete(string id) { CategoryModelOutput categoryModel = new CategoryModelOutput(); try { _logger.Information("Delete Category " + id); UserSessionManager usrSession = new UserSessionManager(); var user = User as ClaimsPrincipal; string userId = user.Claims.Where(c => c.Type == "USERID").Select(c => c.Value).SingleOrDefault(); CategoryServices categoryServices = new CategoryServices { objUser = usrSession.UserLog(userId)._userInfo }; var response = categoryServices.Delete(id); categoryModel.IsSuccess = true; categoryModel.Message = "Success Delete"; categoryModel.Code = 200; } catch (Exception ex) { _logger.Error("delete Category" + ex.Message); categoryModel.IsSuccess = false; categoryModel.Message = "Failed Delete" + ex.Message; categoryModel.Code = 422; } return(Ok(categoryModel)); }
public IHttpActionResult Get() { CategoryServices categoryService = CreateCategoryService(); var category = categoryService.GetAll(); return(Ok(category)); }
public void IsCategoryAlreadyPresent_ShouldThrowArgumentExceptionAndCorrectMessage_WhenCategoryAlreadyInDb() { var options = TestUtils.GetOptions(nameof(IsCategoryAlreadyPresent_ShouldThrowArgumentExceptionAndCorrectMessage_WhenCategoryAlreadyInDb)); using (var arrangeContext = new MovInfoContext(options)) { var mockBusinessValidator = new Mock <IBusinessLogicValidator>(); var service = new CategoryServices(arrangeContext, mockBusinessValidator.Object); var addedCategory = service.AddCategoryAsync( TestSamples.exampleCategory.Title, TestSamples.allowedRoles); arrangeContext.SaveChanges(); } using (var assertContext = new MovInfoContext(options)) { var mockWrapUserManager = new Mock <IWrapUserManager>(); var mockHttpContext = new Mock <IHttpContextAccessor>(); var sut = new BusinessLogicValidator(mockHttpContext.Object, mockWrapUserManager.Object); var ex = Assert.ThrowsException <ArgumentException>(() => sut.IsCategoryAlreadyPresent(assertContext, TestSamples.exampleCategory.Title)); Assert.AreEqual(ex.Message, BusinessLogicValidatorMessages.CategoryAlreadyPresent); } }
public ActionResult Categories() { CategoryServices cs = new CategoryServices(); ViewBag.categories = cs.GetMany().ToList(); return(View()); }
public ActionResult Create() { CategoryServices categoryServices = new CategoryServices(); var categories = categoryServices.GetCategories(); return(PartialView(categories)); }
public HttpResponseMessage PostCategory(Category category) { var createdCategory = CategoryServices.CreateCategory(category); // If product already exists within database, return 409. if (createdCategory == null) { var alreadyExistsResponse = Request.CreateResponse (HttpStatusCode.Conflict, "(409) Category already exists", Configuration.Formatters.JsonFormatter); alreadyExistsResponse.Headers.Add("API-Version", apiVersion); alreadyExistsResponse.Headers.Add("ERROR", "(409) Resource already exists"); return(alreadyExistsResponse); } // Product doesn't exist inside the database, proceed. else { var response = Request.CreateResponse(HttpStatusCode.Created, category, Configuration.Formatters.JsonFormatter); response.Headers.Add("API-Version", apiVersion); response.Headers.Add("Response-Type", "JSON"); if (Request.RequestUri.AbsoluteUri.EndsWith("/")) { response.Headers.Add("New-Category-URL", Request.RequestUri.AbsoluteUri + createdCategory.ID); } else { response.Headers.Add("New-Category-URL", Request.RequestUri.AbsoluteUri + "/" + createdCategory.ID); } return(response); } }
public ActionResult Index() { if (Session["UserId"] != null) { List <Batches> Batches = new List <Batches>(); int UserId = Convert.ToInt32(Session["UserId"]); View_UserDetails Userdetails = UserDetailsViewService.GetUserByUserId(Convert.ToInt32(UserId)); List <YearsforFaculty> Years = new List <YearsforFaculty>(); if (Userdetails.RoleId == "2") { for (int?i = Userdetails.WorkingFrom; i <= Userdetails.WorkingTo; i++) { Years.Add(new YearsforFaculty { Year = Convert.ToString(i) }); } } WhiteBoardModel WhiteBoard = new WhiteBoardModel() { Viewdetails = Batches, RoleId = Userdetails.RoleId, Batch = Userdetails.Batch, Stream = Userdetails.CourseName, Events = EventCategoryService.GetCategorys(), yearsList = Years, Coursecategorys = CategoryServices.GetAllCourseCategories(), }; // ViewBag.Userdata = GenericMethods.GetUserdetailsonFaculty(UserId, Convert.ToString(Userdetails.Batch)); return(View(WhiteBoard)); } return(RedirectToAction(LoginPages.Login, LoginPages.Account, new { area = "" })); }
public ActionResult Edit([Bind(Include = "Id, FirstName, LastName, FatherName, MotherName, BirthDate, ExpectedEndDate, CersStartDate, CfStartDate, LeaveDate, LeaveReason, EmployeeStatus, Department, Notes, Category")] Employee employee) { Db db = new Db(DbServices.ConnectionString); if (ModelState.IsValid) { try { EmployeeServices.Update(CurrentUser.Id, employee, db); TempData["Success"] = ResourceServices.GetString(Cf.Data.Resources.ResourceBase.Culture, "UI", "UpdateConfirmed"); return(RedirectToAction("Index")); } catch (CfException cfex) { TempData["Failure"] = cfex.ErrorDefinition.LocalizedMessage; } catch (Exception ex) { TempData["Failure"] = ex.Message; } } ViewBag.CategoryList = new SelectList(CategoryServices.List(db), "Id", "Name", employee.Category); ViewBag.DepartmentList = new SelectList(DepartmentServices.List(db), "Id", "Name", employee.Department); ViewBag.EmployeeStatusList = new SelectList(EmployeeStatusServices.List(db), "Id", "Name", employee.EmployeeStatus); return(View(employee)); }
public IHttpActionResult Get(int id) { CategoryServices categoryService = CreateCategoryService(); var category = categoryService.GetCategoryById(id); return(Ok(category)); }
public void TestMethod1() { var data = new List <Category> { new Category { Id = 4, Name = "Mirko" }, new Category { Id = 2, Name = "Slavko" }, }; var data2 = data.AsQueryable(); var mockSet = new Mock <DbSet <Category> >(); var mockContext = new Mock <TracktorDb>(); mockContext.Setup(m => m.Category).Returns(mockSet.Object); /*mockSet.As<IQueryable<Category>>().Setup(m => m.Provider).Returns(data.Provider); * mockSet.As<IQueryable<Category>>().Setup(m => m.Expression).Returns(data.Expression); * mockSet.As<IQueryable<Category>>().Setup(m => m.ElementType).Returns(data.ElementType); * mockSet.As<IQueryable<Category>>().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator());*/ var cs = new CategoryServices(mockContext.Object); //cs.Insert(new Domain.CategoryEntity() { Id = 4, Name = "7" }); //Assert.AreEqual(1, cs.ListAll().Count, "Wrong count"); }
public void CorrectlyReturnDeleted_Category() { var options = TestUtils.GetOptions(nameof(CorrectlyReturnDeleted_Category)); using (var arrangeContext = new MovInfoContext(options)) { var mockBusinessValidator = new Mock <IBusinessLogicValidator>(); var sut = new CategoryServices(arrangeContext, mockBusinessValidator.Object); var addedCategory = sut.AddCategoryAsync(TestSamples.exampleCategory.Title, TestSamples.allowedRoles); arrangeContext.SaveChanges(); } using (var assertContext = new MovInfoContext(options)) { var mockBusinessValidator = new Mock <IBusinessLogicValidator>(); var sut = new CategoryServices(assertContext, mockBusinessValidator.Object); var deletedCategory = sut.DeleteCategoryAsync( TestSamples.exampleCategory.Id, TestSamples.allowedRoles).Result; Assert.IsInstanceOfType(deletedCategory, typeof(Category)); Assert.AreEqual(deletedCategory.Id, TestSamples.exampleCategory.Id); Assert.AreEqual(deletedCategory.Title, TestSamples.exampleCategory.Title); } }
public IActionResult Store([FromBody] CategoryModel model) { CategoryModelOutput categoryModel = new CategoryModelOutput(); try { if (ModelState.IsValid) { _logger.Information("Post Sub Category " + model.category_name); UserSessionManager usrSession = new UserSessionManager(); var user = User as ClaimsPrincipal; string userId = user.Claims.Where(c => c.Type == "USERID").Select(c => c.Value).SingleOrDefault(); CategoryServices categoryServices = new CategoryServices { objUser = usrSession.UserLog(userId)._userInfo }; model.category_parentid = model.category_parentid; var response = categoryServices.AddSubCategory(model); categoryModel.IsSuccess = true; categoryModel.Message = "Success Saving"; categoryModel.Code = 200; } else { _logger.Error("Post Sub Category " + model.category_name); string errordetails = ""; var errors = new List <string>(); foreach (var state in ModelState) { foreach (var error in state.Value.Errors) { string p = error.ErrorMessage; errordetails = errordetails + error.ErrorMessage; } } Dictionary <string, object> dict = new Dictionary <string, object>(); dict.Add("error", errordetails); categoryModel.IsSuccess = false; categoryModel.Message = "error saving validating"; categoryModel.Code = 422; categoryModel.CustomField = dict; } } catch (Exception ex) { _logger.Error("Post Sub Category" + ex.Message); categoryModel.IsSuccess = false; categoryModel.Message = "Failed Saving" + ex.Message; categoryModel.Code = 422; } return(Ok(categoryModel)); }
public void Constructor_Should_CreateCategoryServices_IfParamsAreValid() { var mockedRepository = new Mock <IRepository <Category> >(); var categoryService = new CategoryServices(mockedRepository.Object); Assert.That(categoryService, Is.InstanceOf <CategoryServices>()); }
public ActionResult Create() { Article article = new Article(); CategoryServices categoryServices = new CategoryServices(); ViewData["Categorylist"] = categoryServices.GetCategorySelectList(1); return(View(article)); }
public DeviceController() { deviceServices = new DeviceServices(); categoryservices = new CategoryServices(); propertyservice = new PropertyServices(); mapper = AutoMapperConfig.Mapper; db = new taskdeviceEntities(); }
// GET: AddItem public AddItemController() { _teamServices = new TeamServices(); _workstreamServices = new WorkstreamServices(); _categoryServices = new CategoryServices(); _subCategoryServices = new SubcategoryServices(); _goalServices = new GoalServices(); }
public void GetAllCategories_Should_NotBeCalled_IfItIsNeverCalled() { var mockedRepository = new Mock <IRepository <Category> >(); var categoryService = new CategoryServices(mockedRepository.Object); mockedRepository.Verify(rep => rep.All(), Times.Never); }
public HomeController() { _teamServices = new TeamsServices(); _wstreamServices = new WStreamsServices(); _categoryServices = new CategoryServices(); _subCategoryServices = new SubcategoryServices(); _agoalServices = new AGoalServices(); }