public DTO.Category CreateCategory(DataAccess.Category category, bool includeOnlyActive = true) { CheckHelper.ArgumentNotNull(category, "category"); CheckHelper.ArgumentWithinCondition(!category.IsNew(), "!category.IsNew()"); return (_dtoCache.Get( category, c => { var result = new DTO.Category { Id = c.Id, Name = c.Name, Active = c.Active }; CopyTrackableFields(result, c); return result; }, (cDto, c) => cDto.SubCategories = c.SubCategories .Where(sc => sc.Active || !includeOnlyActive) .OrderBy(sc => sc.Name) .Select(sc => CreateSubCategory(sc, includeOnlyActive)) .ToArray())); }
public DTO.SubCategory[] GetSubCategories(DTO.Category category, string filter) { CheckHelper.ArgumentNotNull(category, "category"); CheckHelper.ArgumentWithinCondition(!category.IsNew(), "!category.IsNew()"); CheckHelper.WithinCondition(SecurityService.IsLoggedIn, "User is not logged in."); CheckHelper.WithinCondition(SecurityService.IsCurrentUserSeller, "Only seller can get all subcategories."); var query = Container .Get <IPersistentService>() .GetEntitySet <SubCategory>() .Where(sc => sc.CategoryId == category.Id) .AsQueryable(); if (!string.IsNullOrWhiteSpace(filter)) { query = query.Where(sc => sc.Name.Contains(filter)); } var dtoService = Container.Get <IDtoService>(); return (query .OrderBy(sc => sc.Id) .ToArray() .Select(sc => dtoService.CreateSubCategory(sc, false)) .ToArray()); }
public void UpdateCategory(DTO.Category updatedCategory) { CheckHelper.ArgumentNotNull(updatedCategory, "updatedCategory"); CheckHelper.ArgumentWithinCondition(!updatedCategory.IsNew(), "Category is new."); Container.Get <IValidateService>().CheckIsValid(updatedCategory); CheckHelper.WithinCondition(SecurityService.IsLoggedIn, "User is not logged in."); CheckHelper.WithinCondition(SecurityService.IsCurrentUserSeller, "Only seller can change category."); var persistentService = Container.Get <IPersistentService>(); var category = persistentService.GetEntityById <DataAccess.Category>(updatedCategory.Id); CheckHelper.NotNull(category, "Category does not exist."); if (category.Name != updatedCategory.Name) { var doesAnotherCategoryWithTheSameNameExist = persistentService .GetEntitySet <DataAccess.Category>() .Any(c => c.Name == updatedCategory.Name); if (doesAnotherCategoryWithTheSameNameExist) { throw new CategoryServiceException("Категория с заданным названием уже существует."); } } category.Name = updatedCategory.Name; category.Active = updatedCategory.Active; category.UpdateTrackFields(Container); persistentService.SaveChanges(); }
public void setDefault() { btnSave.Visible = true; btnEdit.Visible = false; txtCategory.Focus(); txtCategory.Text = ""; Ob = SetValue(); grdCategory.DataSource = BAL.BALFactory.Instance.BL_CategoryMaster.ShowAll(Ob); grdCategory.DataBind(); }
public DTO.Category SetValue() { Ob = new DTO.Category(); Ob.CategoryName = txtCategory.Text.ToUpper(); Ob.Active = 1; Ob.CategoryID = lblUpdateId.Text; Ob.BranchId = Globals.BranchID; Ob.ImageName = hdnImageName.Value; return(Ob); }
public DataSet ShowAll(DTO.Category Ob) { SqlCommand cmd = new SqlCommand(); DataSet ds = new DataSet(); cmd.CommandText = "sp_Category"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@BranchId", Ob.BranchId); cmd.Parameters.AddWithValue("@Flag", 3); ds = PrjClass.GetData(cmd); return(ds); }
public string DeleteCategory(DTO.Category Ob) { SqlCommand cmd = new SqlCommand(); string res = string.Empty; cmd.CommandText = "sp_Category"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@CategoryId", Ob.CategoryID); cmd.Parameters.AddWithValue("@BranchId", Ob.BranchId); cmd.Parameters.AddWithValue("@Flag", 5); res = PrjClass.ExecuteNonQuery(cmd); return(res); }
public List <DTO.Category> GetListCategory() { List <DTO.Category> list = new List <DTO.Category>(); string query = "Select * from FOODCATEGORY"; DataTable data = DAO.DataProvider.Instance.ExecuteQuery(query); foreach (DataRow item in data.Rows) { DTO.Category category = new DTO.Category(item); list.Add(category); } return(list); }
public DTO.Category GetCategoryByID(int id) { DTO.Category category = null; string query = "Select * from FOODCATEGORY where id = " + id; DataTable data = DAO.DataProvider.Instance.ExecuteQuery(query); foreach (DataRow item in data.Rows) { category = new DTO.Category(item); return(category); } return(category); }
public string SaveCategoryMaster(DTO.Category Ob) { ArrayList date = DAL.DALFactory.Instance.DAL_DateAndTime.getDateAndTimeAccordingToZoneTime(Ob.BranchId); string res = string.Empty; SqlCommand cmd = new SqlCommand(); cmd.CommandText = "sp_Category"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@CategoryName", Ob.CategoryName); cmd.Parameters.AddWithValue("@CategoryImage", Ob.ImageName); cmd.Parameters.AddWithValue("@Active", Ob.Active); cmd.Parameters.AddWithValue("@DateCreated", date[0].ToString()); cmd.Parameters.AddWithValue("@DateModified", date[0].ToString()); cmd.Parameters.AddWithValue("@BranchId", Ob.BranchId); cmd.Parameters.AddWithValue("@Flag", 1); res = PrjClass.ExecuteNonQuery(cmd); return(res); }
protected void btnDelete_Click(object sender, EventArgs e) { string res = ""; Ob = SetValue(); Ob.Active = 0; res = BAL.BALFactory.Instance.BL_CategoryMaster.DeleteCategory(Ob); if (res == "Record Saved") { lblMsg.Text = "Record Deactivated"; btnDelete.Visible = false; setDefault(); img.ImageUrl = ""; } else { lblErr.Text = res; } }
protected void btnSave_Click(object sender, EventArgs e) { if (fltImage.Value != "") { btnUpload_Click(null, null); } string res = ""; Ob = SetValue(); res = BAL.BALFactory.Instance.BL_CategoryMaster.SaveCategoryMaster(Ob); if (res == "Record Saved") { lblMsg.Text = res; setDefault(); } else { lblErr.Text = res; } }
public void CreateCategory_Should_Create_Category() { // Arrange var container = ContainerMockFactory.Create(); var securityService = container.Get <ISecurityService>(); securityService.LogIn(UserMockFactory.Diana.Login, EncryptServiceMockFactory.DianaPasswordData.Password); const string NEW_CATEGORY_NAME = "New Category"; var createdCategory = new DTO.Category { Name = NEW_CATEGORY_NAME, Active = true }; var categoryService = container.Get <ICategoryService>(); var persistentService = container.Get <IPersistentService>(); var timeService = container.Get <ITimeService>(); // Act categoryService.CreateCategory(createdCategory); // Assert var actualCategory = persistentService .GetEntitySet <DataAccess.Category>() .Single(c => c.Name == NEW_CATEGORY_NAME); Assert.IsTrue(actualCategory.Id > 0); Assert.AreEqual(NEW_CATEGORY_NAME, actualCategory.Name); Assert.IsTrue(actualCategory.Active); Assert.AreEqual(timeService.UtcNow, actualCategory.CreateDate); Assert.AreEqual(timeService.UtcNow, actualCategory.ChangeDate); Assert.AreEqual(UserMockFactory.Diana, actualCategory.CreatedBy); Assert.AreEqual(UserMockFactory.Diana, actualCategory.ChangedBy); Assert.AreEqual(createdCategory, container.Get <IDtoService>().CreateCategory(actualCategory)); }
public void CreateCategory(DTO.Category createdCategory) { CheckHelper.ArgumentNotNull(createdCategory, "createdCategory"); CheckHelper.ArgumentWithinCondition(createdCategory.IsNew(), "Category is not new."); Container.Get <IValidateService>().CheckIsValid(createdCategory); CheckHelper.WithinCondition(SecurityService.IsLoggedIn, "User is not logged in."); CheckHelper.WithinCondition(SecurityService.IsCurrentUserSeller, "Only seller can create category."); var persistentService = Container.Get <IPersistentService>(); var doesAnotherCategoryWithTheSameNameExist = persistentService .GetEntitySet <DataAccess.Category>() .Any(c => c.Name == createdCategory.Name); if (doesAnotherCategoryWithTheSameNameExist) { throw new CategoryServiceException("Категория с заданным названием уже существует."); } var category = new DataAccess.Category { Name = createdCategory.Name, Active = createdCategory.Active }; category.UpdateTrackFields(Container); persistentService.Add(category); persistentService.SaveChanges(); createdCategory.Id = category.Id; createdCategory.CreateDate = category.CreateDate; createdCategory.CreateUser = category.CreatedBy.GetFullName(); createdCategory.ChangeDate = category.ChangeDate; createdCategory.ChangeUser = category.ChangedBy.GetFullName(); }
public void UpdateCategory_Should_Update_Category_When_Name_Is_Not_Changed() { // Arrange var container = ContainerMockFactory.Create(); var securityService = container.Get <ISecurityService>(); securityService.LogIn(UserMockFactory.Diana.Login, EncryptServiceMockFactory.DianaPasswordData.Password); var name = CategoryMockFactory.Women.Name; var createDate = CategoryMockFactory.Women.CreateDate; var createdBy = CategoryMockFactory.Women.CreatedBy; var updatedCategory = new DTO.Category { Id = CategoryMockFactory.Women.Id, Name = CategoryMockFactory.Women.Name, Active = false }; var categoryService = container.Get <ICategoryService>(); var persistentService = container.Get <IPersistentService>(); var timeService = container.Get <ITimeService>(); // Act categoryService.UpdateCategory(updatedCategory); // Assert var actualCategory = persistentService.GetEntityById <DataAccess.Category>(CategoryMockFactory.Women.Id); Assert.AreEqual(name, actualCategory.Name); Assert.IsFalse(actualCategory.Active); Assert.AreEqual(createDate, actualCategory.CreateDate); Assert.AreEqual(timeService.UtcNow, actualCategory.ChangeDate); Assert.AreEqual(createdBy, actualCategory.CreatedBy); Assert.AreEqual(UserMockFactory.Diana, actualCategory.ChangedBy); Assert.AreEqual(updatedCategory, container.Get <IDtoService>().CreateCategory(actualCategory)); }
private void btnSave_Click(object sender, EventArgs e) { if (id == 0) { if (txtName.Text == "") { MessageBox.Show("សូមបំពេញពត៏មានឲ្យបានត្រឹមត្រូវ!!!"); } else { DTO.Category category = new DTO.Category(txtName.Text); if (new CategoryDAO().AddCategory(category)) { txtName.Clear(); dgvCategory.DataSource = new DAO.CategoryDAO().GetAllCategories().Tables[0]; id = 0; } else { MessageBox.Show("ប្រតិបត្តិការណ៍បរាជ័យ!!!"); } } } else { DTO.Category cat = new DTO.Category(id, txtName.Text); if (new CategoryDAO().UdateCategory(cat)) { txtName.Clear(); dgvCategory.DataSource = new DAO.CategoryDAO().GetAllCategories().Tables[0]; id = 0; btnDelete.Visible = false; } else { } } }
private ICollection <DTO.Category> ConvertToDTO(ICollection <Category> categories) { var dtoCategories = new List <DTO.Category>(); foreach (var category in categories) { var dtoCategory = new DTO.Category { Name = category.Name, Id = category.Id }; if (category.Childs.Count > 0) { dtoCategory.Childs = ConvertToDTO(category.Childs).ToList(); } dtoCategories.Add(dtoCategory); } return(dtoCategories); }
public void CreateCategory_Should_Throw_Exception_When_Current_User_Is_Not_Seller() { // Arrange var container = ContainerMockFactory.Create(); var securityService = container.Get <ISecurityService>(); securityService.LogIn(UserMockFactory.Olesya.Login, EncryptServiceMockFactory.OlesyaPasswordData.Password); var createdCategory = new DTO.Category { Name = "New Category", Active = true }; var categoryService = container.Get <ICategoryService>(); // Act // Assert ExceptionAssert.Throw <InvalidOperationException>( () => categoryService.CreateCategory(createdCategory), "Only seller can create category."); }
public void UpdateCategory_Should_Throw_Exception_When_Category_With_The_Same_Name_Already_Exists() { var container = ContainerMockFactory.Create(); var securityService = container.Get <ISecurityService>(); securityService.LogIn(UserMockFactory.Diana.Login, EncryptServiceMockFactory.DianaPasswordData.Password); var updatedCategory = new DTO.Category { Id = CategoryMockFactory.Women.Id, Name = CategoryMockFactory.Men.Name, Active = true }; var categoryService = container.Get <ICategoryService>(); // Act // Assert ExceptionAssert.Throw <CategoryServiceException>( () => categoryService.UpdateCategory(updatedCategory), "Категория с заданным названием уже существует."); }
private void ParseResult(HttpResponseMessage result) { try { var content = result.Content.ReadAsStringAsync().Result; if (content != "null") { DTO.Category[] categoryRtn = JsonConvert.DeserializeObject <DTO.Category[]>(content); if (categoryRtn.Length > 0) { if (!_category.Exists) { _category = categoryRtn.First(); } foreach (var eCategory in categoryRtn) { var idCategory = eCategory.id_category.GetValueOrDefault(-1); } } } } catch (Exception ex) { ErrorHelper.Handle(ex); } }
/// <summary> /// Generates a <see cref="DTO.Thing"/> from the current <see cref="Category"/> /// </summary> public override DTO.Thing ToDto() { var dto = new DTO.Category(this.Iid, this.RevisionNumber); dto.Alias.AddRange(this.Alias.Select(x => x.Iid)); dto.Definition.AddRange(this.Definition.Select(x => x.Iid)); dto.ExcludedDomain.AddRange(this.ExcludedDomain.Select(x => x.Iid)); dto.ExcludedPerson.AddRange(this.ExcludedPerson.Select(x => x.Iid)); dto.HyperLink.AddRange(this.HyperLink.Select(x => x.Iid)); dto.IsAbstract = this.IsAbstract; dto.IsDeprecated = this.IsDeprecated; dto.ModifiedOn = this.ModifiedOn; dto.Name = this.Name; dto.PermissibleClass.AddRange(this.PermissibleClass); dto.RevisionNumber = this.RevisionNumber; dto.ShortName = this.ShortName; dto.SuperCategory.AddRange(this.SuperCategory.Select(x => x.Iid)); dto.ThingPreference = this.ThingPreference; dto.IterationContainerId = this.CacheKey.Iteration; dto.RegisterSourceThing(this); this.BuildDtoPartialRoutes(dto); return(dto); }
private void btnSave_Click(object sender, EventArgs e) { if (id == 0) { if ( txtBarcode.Text.Trim() == "" || txtProductCode.Text.Trim() == "" || txtName.Text.Trim() == "" // || cboCategory.SelectedValue == "" || txtPriceIn.Text.Trim() == "" || txtPriceOut.Text.Trim() == "" ) { MessageBox.Show("សូមបំពេញពត៏មានឲ្យបានត្រឹមត្រូវ!!!"); } else { DAO.ProductDAO productDAO = new DAO.ProductDAO(); if (productDAO.checkProduct(txtProductCode.Text)) { MessageBox.Show("លេខកូដទំនិញរបស់លោកអ្នកមានរួចហើយ សូមបញ្ចូលលេខកូដទំនិញផ្សេង"); return; } DTO.Staff staff = new DTO.Staff(); staff.Staffid = UserSession.Session.Staff.Staffid;// Data.user.Staffid; DTO.Category cate = new DTO.Category(); cate.Categoryid = (int)cboCategory.SelectedValue; DTO.Product product = new DTO.Product(0,txtProductCode.Text.Trim(), txtBarcode.Text.Trim(), txtName.Text.Trim(), txtDescription.Text.Trim(), Decimal.Parse(txtPriceIn.Text.Trim()), Decimal.Parse(txtPriceOut.Text.Trim()), txtRemark.Text.Trim(), staff, staff, cate); if (new DAO.ProductDAO().addProduct(product)) { ClearForm(); dgvProduct.DataSource = new DAO.ProductDAO().getAllProductDS().Tables[0]; id = 0; } else { MessageBox.Show("ប្រតិបត្តិការណ៍បរាជ័យ!!!"); } } } else { if (txtBarcode.Text.Trim() == "" || txtProductCode.Text.Trim() == "" || txtName.Text.Trim() == "" // || cboCategory.SelectedValue == "" || txtPriceIn.Text.Trim() == "" || txtPriceOut.Text.Trim() == "" ) { MessageBox.Show("សូមបំពេញពត៏មានឲ្យបានត្រឹមត្រូវ!!!"); } else { DTO.Staff staff = new DTO.Staff(); staff.Staffid = UserSession.Session.Staff.Staffid;// Data.user.Staffid; DTO.Category cate = new DTO.Category(); cate.Categoryid = (int)cboCategory.SelectedValue; DTO.Product product = new DTO.Product(id, txtProductCode.Text.Trim(), txtBarcode.Text.Trim(), txtName.Text.Trim(), txtDescription.Text.Trim(), Decimal.Parse(txtPriceIn.Text.Trim()), Decimal.Parse(txtPriceOut.Text.Trim()), txtRemark.Text.Trim(), staff, staff, cate); if (new DAO.ProductDAO().updateProduct(product)) { ClearForm(); dgvProduct.DataSource = new DAO.ProductDAO().getAllProductDS().Tables[0]; id = 0; delete.Visible = false; } else { MessageBox.Show("ប្រតិបត្តិការណ៍បរាជ័យ!!!"); } } } }
public static Models.Category ToModel(this DTO.Category DTOObject) { Mapper.Initialize(p => p.CreateMap <DTO.Category, Models.Category>()); return(Mapper.Map <Models.Category>(DTOObject)); }
public DataSet ShowAll(DTO.Category Ob) { return(DAL.DALFactory.Instance.DAL_CategoryMaster.ShowAll(Ob)); }
public DataSet BindGridView(DTO.Category Ob) { return(DAL.DALFactory.Instance.DAL_CategoryMaster.BindGridView(Ob)); }
public Task SaveCategory(DTO.Category category) { return(_categoryBusiness.SaveCategory(_mapperService.Map <Category>(category))); }
public string DeleteCategory(DTO.Category Ob) { return(DAL.DALFactory.Instance.DAL_CategoryMaster.DeleteCategory(Ob)); }
public string SaveCategoryMaster(DTO.Category Ob) { return(DAL.DALFactory.Instance.DAL_CategoryMaster.SaveCategoryMaster(Ob)); }
protected void btnSearch_Click(object sender, EventArgs e) { Ob = SetValue(); grdCategory.DataSource = BAL.BALFactory.Instance.BL_CategoryMaster.BindGridView(Ob); grdCategory.DataBind(); }
public static void UpdateLoaiSP(DTO.Category loai) { string sql = "update LOAIMON set TenLoai = N'" + loai.TenLoai + "' where id = '" + loai.Id + "'"; KetNoiCSDL.NonQuery(sql); }