public IEnumerable <ICategoriesModel> GetAll() { var listcategoriesDto = new List <CategoriesModel>(); string query = "select Id, Name, SupplierId, Link, Rate, Notes from Categories order by Name"; using (var db = new SqlCeConnection(connectionString)) { db.Open(); using (SqlCeCommand command = new SqlCeCommand(query, db)) { using (SqlCeDataReader reader = command.ExecuteReader()) { while (reader.Read()) { var categoryDto = new CategoriesModel { Id = Convert.ToInt32(reader["Id"]), Name = reader["Name"].ToString(), SupplierId = Convert.ToInt32(reader["SupplierId"]), Link = reader["Link"].ToString(), Rate = Convert.ToDecimal(reader["Rate"]), Notes = reader["Notes"].ToString() }; listcategoriesDto.Add(categoryDto); } } } db.Close(); } return(listcategoriesDto); }
public ICategoriesModel GetById(int id) { CategoriesModel category = new CategoriesModel(); using (var db = new SqlCeConnection(connectionString)) { db.Open(); string query = "select Id, Name, SupplierId, Link, Rate, Notes from Categories where c.Id=@Id"; using (SqlCeCommand cmd = new SqlCeCommand(query, db)) { cmd.Prepare(); cmd.Parameters.AddWithValue("@Id", id); using (SqlCeDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { category.Id = Convert.ToInt32(reader["Id"]); category.Name = reader["Name"].ToString(); category.SupplierId = Convert.ToInt32(reader["SupplierId"]); category.Link = reader["Link"].ToString(); category.Rate = Convert.ToDecimal(reader["Rate"]); category.Notes = reader["Notes"].ToString(); } } } db.Close(); } return(category); }
public ActionResult Create() { WorkContext.Breadcrumbs.Add(new Breadcrumb { Text = T("Quản lý chuyên mục"), Url = "#" }); WorkContext.Breadcrumbs.Add(new Breadcrumb { Text = T("Thêm thông tin chuyên mục"), Url = Url.Action("Index") }); var model = new CategoriesModel(); var result = new ControlFormResult <CategoriesModel>(model); result.Title = this.T("Thêm thông chuyên mục"); result.FormMethod = FormMethod.Post; result.UpdateActionName = "Update"; result.ShowCancelButton = false; result.ShowBoxHeader = false; result.FormWrapperStartHtml = Constants.Form.FormWrapperStartHtml; result.FormWrapperEndHtml = Constants.Form.FormWrapperEndHtml; result.RegisterExternalDataSource(x => x.ParentId, BindCategories()); result.AddAction().HasText(this.T("Thêm mới")).HasUrl(this.Url.Action("Create")).HasButtonStyle(ButtonStyle.Success); result.AddAction().HasText(this.T("Back")).HasUrl(this.Url.Action("Index")).HasButtonStyle(ButtonStyle.Danger); return(result); }
public ActionResult Edit(int id) { WorkContext.Breadcrumbs.Add(new Breadcrumb { Text = T("Quản lý chuyên mục"), Url = "#" }); WorkContext.Breadcrumbs.Add(new Breadcrumb { Text = T("Thông tin chuyên mục"), Url = Url.Action("Index") }); var model = new CategoriesModel(); if (id > 0) { var service = WorkContext.Resolve <ICategoriesService>(); model = service.GetById(id); } var result = new ControlFormResult <CategoriesModel>(model); result.Title = this.T("Thông tin chuyên mục"); result.FormMethod = FormMethod.Post; result.UpdateActionName = "Update"; result.ShowCancelButton = false; result.ShowBoxHeader = false; result.FormWrapperStartHtml = Constants.Form.FormWrapperStartHtml; result.FormWrapperEndHtml = Constants.Form.FormWrapperEndHtml; result.RegisterExternalDataSource(x => x.ParentId, y => BindCategoriesParent()); result.AddAction().HasText(this.T("Clear")).HasUrl(this.Url.Action("Edit", RouteData.Values.Merge(new { id = 0 }))).HasButtonStyle(ButtonStyle.Success); result.AddAction().HasText(this.T("Back")).HasUrl(this.Url.Action("Index")).HasButtonStyle(ButtonStyle.Danger); return(result); }
//------------------------------------------------------------------------------------------------------ #endregion #region /*--------- Create ---------*\ //------------------------------------------------------------------------------------------------------ /// <summary> /// Converts the object properties to SQL paramters and executes the create procedure /// and updates the object with the SQL data by reference. /// </summary> /// <param name="CategoriesObj">Model object.</param> /// <returns>The result of create query.</returns> //-------------------------------------------------------------------- public bool Create(CategoriesModel CategoriesObj) { bool result = false; using (SqlConnection myConnection = GetSqlConnection()) { SqlCommand myCommand = new SqlCommand("[dbo].[Categories_Create]", myConnection); myCommand.CommandType = CommandType.StoredProcedure; //---------------------------------------------------------------------------------------------- // Set the parameters //---------------------------------------------------------------------------------------------- myCommand.Parameters.Add("@CategoryID", SqlDbType.Int, 4).Direction = ParameterDirection.Output; myCommand.Parameters.Add("@Title", SqlDbType.NVarChar, 50).Value = CategoriesObj.Title; //---------------------------------------------------------------------------------------------- // Execute the command //---------------------------------------------------------------------------------------------- myConnection.Open(); if (myCommand.ExecuteNonQuery() > 0) { result = true; //Get ID value from database and set it in object CategoriesObj.CategoryID = (int)myCommand.Parameters["@CategoryID"].Value; } myConnection.Close(); return result; //---------------------------------------------------------------------------------------------- } }
public SideMenuViewModel(BrandsModel brandsModel, CategoriesModel categoriesModel) { brandList = brandsModel.data; categoryList = categoriesModel.data; ConstructSideMenu(brandList, categoryList); }
public ActionResult Add(CategoriesModel input) { if (ModelState.IsValid) { input.UserId = SessionHelper.GetSessionUser().UserId; input.Taxonomy = input.Taxonomy ?? "Content"; input.Status = input.Status ?? true; input.Order = input.Order ?? 0; input.Date = input.Date ?? DateTime.Now; input.Modified = input.Modified ?? DateTime.Now; var entity = new tb_Catogory(); entity.Date = input.Date; entity.Meta_Description = input.Meta_Description; entity.Meta_Keyword = input.Meta_Keyword; entity.Meta_Title = input.Meta_Title; entity.Modified = input.Modified; entity.Name = input.Name; entity.Order = input.Order; entity.ParentId = input.ParentId; entity.Slug = input.Slug; entity.Status = input.Status; entity.Taxonomy = input.Taxonomy; entity.Thumbnail = input.Thumbnail; entity.Title = input.Title; entity.UserId = input.UserId; long Id = Dao.Insert(entity); return(RedirectToAction("Edit", "Categories", new { Id = Id })); } ViewBag.ParentId = new SelectList(Dao.ListAllByTaxonomy("Content"), "Id", "Name", input.ParentId); return(View(input)); }
public IResult Update(CategoriesViewModel instance) { if (instance == null) { throw new ArgumentNullException(); } IResult result = new Result(false); try { var category = new CategoriesModel(); category.CategoryID = instance.CategoryID; category.CategoryName = instance.CategoryName; category.Description = instance.Description; category.Picture = instance.Picture; _repository.categories.Update(category); result.Success = true; } catch (Exception ex) { result.Exception = ex; } return(result); }
public IActionResult test3() { CategoriesModel categoriesModel = new CategoriesModel(); categoriesModel.Name = "asp.net-mvc-4"; categoriesModel.CreaDate = DateTime.Now; List <ConversationsModel> conversationsModels = new List <ConversationsModel>(); var Questionslist = _dbContext.Questions; var max = Questionslist.Max(x => x.Similar); for (int i = 0; i < max; i++) { var lists = Questionslist.Where(x => x.Similar == i); foreach (var item in lists) { if (!String.IsNullOrEmpty(item.TextDescription) && !String.IsNullOrEmpty(item.HtmlAnswers)) { ConversationsModel conversationsModel = new ConversationsModel(); conversationsModel.Question = AskCaro_QuestionnaireAspirateur.AnalyzerText.GetTag(item.TextDescription); conversationsModel.HtmlAnswers = "<div>" + item.HtmlAnswers.Replace("\n", string.Empty).Replace("\r", string.Empty) + "</div>"; conversationsModel.Categories = categoriesModel; conversationsModel.CreaDate = DateTime.Now; conversationsModels.Add(conversationsModel); } } } _dbContext.Conversations.AddRange(conversationsModels); var resusslt = _dbContext.SaveChanges(); return(View()); }
public ActionResult Edit(CategoriesModel entity) { if (ModelState.IsValid) { entity.UserId = SessionHelper.GetSessionUser().UserId; entity.Taxonomy = entity.Taxonomy ?? "Content"; entity.Status = entity.Status ?? true; entity.Order = entity.Order ?? 0; entity.Date = entity.Date ?? DateTime.Now; entity.Modified = entity.Modified ?? DateTime.Now; var input = new tb_Catogory(); input.Date = entity.Date; input.Id = entity.Id; input.Meta_Description = entity.Meta_Description; input.Meta_Keyword = entity.Meta_Keyword; input.Meta_Title = entity.Meta_Title; input.Modified = entity.Modified; input.Name = entity.Name; input.Order = entity.Order; input.ParentId = entity.ParentId; input.Slug = entity.Slug; input.Status = entity.Status; input.Taxonomy = entity.Taxonomy; input.Thumbnail = entity.Thumbnail; input.Title = entity.Title; input.UserId = entity.UserId; Dao.Update(input); } ViewBag.ParentId = new SelectList(Dao.ListAllByTaxonomy("Content"), "Id", "Name", entity.ParentId); return(View(entity)); }
public IActionResult test2() { CategoriesModel categoriesModel = new CategoriesModel(); categoriesModel.Name = "trivia"; categoriesModel.CreaDate = DateTime.Now; List <ConversationsModel> conversationsModels = new List <ConversationsModel>(); var lines = System.IO.File.ReadLines(@"C:\Users\ahmed\source\repos\AskCaro\AskCaro\MachineLearning\Data\trivia.yml").ToList(); for (int i = 0; i < lines.Count(); i = i + 2) { int j = i; if (j < lines.Count() - 2) { ConversationsModel conversationsModel = new ConversationsModel(); conversationsModel.Question = lines[j].Replace("-", ""); conversationsModel.HtmlAnswers = lines[++j].Replace(" -", ""); conversationsModel.Categories = categoriesModel; conversationsModel.CreaDate = DateTime.Now; conversationsModels.Add(conversationsModel); } } _dbContext.Conversations.AddRange(conversationsModels); var resusslt = _dbContext.SaveChanges(); return(View()); }
public HttpResponseMessage Delete(int id) { int check = new SessionHelper().checkSession(Constants.USERS, Constants.ACTION_DELETE); if (check > 0) { CategoriesModel model = new CategoriesModel(); int resultQuery = model.Delete(id); if (resultQuery != Constants.PROCESS_FAILED) { JArray result = new JArray(); var data = model.GetAll(resultQuery); result = JArray.FromObject(data); var exception = JObject.FromObject(new { err = Constants.PROCESS_OK, data = result }); return(Request.CreateResponse(HttpStatusCode.OK, exception)); } else { JObject exception = JObject.FromObject(new { err = Constants.PROCESS_FAILED, msg = Constants.DELETE_FAIL }); return(Request.CreateResponse(HttpStatusCode.OK, exception)); } } else { string message = (check == Constants.PERMISSION_LOGIN_CODE) ? Constants.PERMISSION_LOGIN_MSG : Constants.PERMISSION_DENIED_MSG; JObject exception = JObject.FromObject(new { err = check, msg = message }); return(Request.CreateResponse(HttpStatusCode.OK, exception)); } }
public ActionResult Index() { var model = new CategoriesModel(); model.CategoryNames = GetCategoryNames(); return(View(model)); }
// Method ListForExcel public void ListForExcel(MetroGrid grid, string keyword, string sortColumn, string sortBy) { grid.Rows.Clear(); grid.Columns.Clear(); List <CategoriesModel> stuffs = CategoriesDao.Instance.ListForExcel(keyword, !string.IsNullOrEmpty(sortColumn) ? HelperBll.GetColumnNameInSQLByPropertyName <CategoriesModel>(sortColumn) : "", sortBy); CategoriesModel nameOf = new CategoriesModel(); grid.Columns.Add(nameof(nameOf.Name), nameof(nameOf.Name)); grid.Columns.Add(nameof(nameOf.CreatedDate), nameof(nameOf.CreatedDate)); grid.Columns.Add(nameof(nameOf.CreatedBy), nameof(nameOf.CreatedBy)); grid.Columns.Add(nameof(nameOf.ModifiedDate), nameof(nameOf.ModifiedDate)); grid.Columns.Add(nameof(nameOf.ModifiedBy), nameof(nameOf.ModifiedBy)); grid.Columns.Add(nameof(nameOf.CountStuffs), nameof(nameOf.CountStuffs)); for (int i = 0; i < stuffs.Count; i++) { grid.Rows.Add(); grid[nameof(nameOf.Name), i].Value = stuffs[i].Name; grid[nameof(nameOf.CreatedDate), i].Value = stuffs[i].CreatedDate; grid[nameof(nameOf.CreatedBy), i].Value = stuffs[i].CreatedBy; grid[nameof(nameOf.ModifiedDate), i].Value = stuffs[i].ModifiedDate.ToString() == "01-Jan-01 12:00:00 AM" ? "" : stuffs[i].ModifiedDate.ToString(); grid[nameof(nameOf.ModifiedBy), i].Value = stuffs[i].ModifiedBy; grid[nameof(nameOf.CountStuffs), i].Value = stuffs[i].CountStuffs; } }
public ActionResult Edit(long?Id) { if (Id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var entity = Dao.Detail(Id); if (entity == null) { return(HttpNotFound()); } var output = new CategoriesModel(); output.Date = entity.Date; output.Id = entity.Id; output.Meta_Description = entity.Meta_Description; output.Meta_Keyword = entity.Meta_Keyword; output.Meta_Title = entity.Meta_Title; output.Modified = entity.Modified; output.Name = entity.Name; output.Order = entity.Order; output.ParentId = entity.ParentId; output.Slug = entity.Slug; output.Status = entity.Status; output.Taxonomy = entity.Taxonomy; output.Thumbnail = entity.Thumbnail; output.Title = entity.Title; output.UserId = entity.UserId; ViewBag.ParentId = new SelectList(Dao.ListAllByTaxonomy("Content"), "Id", "Name", output.ParentId); return(View(output)); }
public List <CategoriesModel> RetrieveAllCategories() { List <CategoriesModel> NewsCategories = new List <CategoriesModel>(); try { _DataTable = new MySqlNewsData().GetAllCategories(); foreach (DataRow row in _DataTable.Rows) { CategoriesModel Category = new CategoriesModel { Name = Convert.ToString(row["Name"]), ID = Convert.ToInt32(row["ID"]), Filter = Convert.ToBoolean(row["Filter"]) }; NewsCategories.Add(Category); } } catch (Exception exception) { Log.Error(exception); } return(NewsCategories); }
public TestCategoriesController() { var mappingConfig = new MapperConfiguration(cfg => { cfg.AddProfile(new JeopardyMappingProfile()); }); model = new CategoriesModel() { Id = 35, CategoryNameEn = "FiveCATS", CategoryNameFr = "TestCat 5 en francais" }; updateModel = new CategoriesModel() { Id = 34, CategoryNameEn = "FiveCATEGORIES", CategoryNameFr = "TestCat 5 en francaisss" }; var mapper = mappingConfig.CreateMapper(); // Use this mapper to instantiate your class _mapper = mapper; _service = new JeopardyRepositoryFake(testContext); _controller = new CategoriesController(_service, _mapper); }
//------------------------------------------------------------------------------------------------------ #endregion #region /*--------- Updat ---------*\ //------------------------------------------------------------------------------------------------------ /// <summary> /// Converts the object properties to SQL paramters and executes the update procedure. /// </summary> /// <param name="CategoriesObj">Model object.</param> /// <returns>The result of update query.</returns> //-------------------------------------------------------------------- public bool Updat(CategoriesModel CategoriesObj) { bool result = false; using (SqlConnection myConnection = GetSqlConnection()) { SqlCommand myCommand = new SqlCommand("[dbo].[Categories_Update]", myConnection); myCommand.CommandType = CommandType.StoredProcedure; //---------------------------------------------------------------------------------------------- // Set the parameters //---------------------------------------------------------------------------------------------- myCommand.Parameters.Add("@CategoryID", SqlDbType.Int, 4).Value = CategoriesObj.CategoryID; myCommand.Parameters.Add("@Title", SqlDbType.NVarChar, 50).Value = CategoriesObj.Title; //---------------------------------------------------------------------------------------------- // Execute the command //---------------------------------------------------------------------------------------------- myConnection.Open(); if (myCommand.ExecuteNonQuery() > 0) { result = true; } myConnection.Close(); return result; //---------------------------------------------------------------------------------------------- } }
public async Task <IActionResult> Ekle(CategoriesModel cm) { _rep.Add(cm.Category); await _rep.Save(); return(RedirectToAction("Liste", "Categories")); }
public IActionResult Add(CategoriesModel model) { if (ModelState.IsValid) { CategoriesManager.Create(model.Name); return(RedirectToAction("Index")); /*using (var db = new DbContext()) * { * db.Categories.Add(new Categories() * { * Name = model.Name, * }); * * db.SaveChanges(); * * }*/ //model.Id = Categories.Count + 1; //modelis derīgs, var veikt datu saglabāšanu //Categories.Add(model); } return(View(model)); }
public IActionResult Index() { var models = _context.getCategories(); var CategoryModels = models.Select(x => new CategoryModel() { Id = x.Id, Name = x.Name, ImageUrl = x.ImageUrl, ParentCategoryId = x.ParentCategoryId, ChildCategories = x.ChildCategories.Select(p => new CategoryModel() { Id = p.Id, Name = p.Name, ImageUrl = p.ImageUrl, ParentCategoryId = p.ParentCategoryId, }) }); var newmodel = new CategoriesModel { categories = CategoryModels }; ViewBag.list = newmodel; return(PartialView("Index")); }
public async Task <IActionResult> Edit(int id, [Bind("CategoryID,CategoryName,Description,Picture")] CategoriesModel categoriesModel) { if (id != categoriesModel.CategoryID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(categoriesModel); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CategoriesModelExists(categoriesModel.CategoryID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(categoriesModel)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Title,Description,ShortDescription,Image,UrlRus")] CategoriesModel categoriesModel, IFormFile imageFile) { if (id != categoriesModel.Id) { return(NotFound()); } if (imageFile != null) { categoriesModel.Image = ImageHelper.AddImage(_appEnvironment, imageFile); } if (ModelState.IsValid) { try { _context.Update(categoriesModel); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CategoriesModelExists(categoriesModel.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(categoriesModel)); }
public List <CategoriesModel> GetAllCategories() { List <CategoriesModel> output = new List <CategoriesModel>(); try { using (SqlConnection conn = new SqlConnection(ConnectionString)) { conn.Open(); string sql = "Select * from categories;"; SqlCommand cmd = new SqlCommand(sql, conn); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { CategoriesModel model = new CategoriesModel(); model.CategoryID = Convert.ToInt32(reader["categoryID"]); model.CategoryName = Convert.ToString(reader["categoryName"]); output.Add(model); } } } catch (SqlException e) { Console.WriteLine(e.Message); throw; } return(output); }
public IHttpActionResult PutCategoriesModel(int id, CategoriesModel categoriesModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != categoriesModel.Id) { return(BadRequest()); } db.Entry(categoriesModel).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CategoriesModelExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public AdvertisementsSearchModel RestorePreviousValues() { var searchModel = new AdvertisementsSearchModel(); searchModel.TransactionKind = TransactionKind; searchModel.ExpiredAdvertisements = ExpiredAdvertisements; searchModel.SortingBy = SortingBy; searchModel.Sizes.AddRange(Sizes); foreach (var cat in CategoriesModel) { CategoriesModel.Add(cat); } searchModel.AdvertisementsKind = AdvertisementsKind; searchModel.CoordinatesModel.Latitude = CoordinatesModel.Latitude; searchModel.CoordinatesModel.LocationAddress = CoordinatesModel.LocationAddress; searchModel.CoordinatesModel.Longitude = CoordinatesModel.Longitude; searchModel.CoordinatesModel.MaxDistance = CoordinatesModel.MaxDistance; searchModel.Page = Page; if (UserInfo != null) { searchModel.UserInfo = new UserInfoModel(); searchModel.UserInfo.Id = UserInfo.Id; searchModel.UserInfo.UserName = UserInfo.UserName; } return(searchModel); }
public List <CategoriesModel> ReadCategories() { try { OpenSqlConnection(); CreateCommandSc("SelectAllCategories"); SqlDataReader sqlDataReader = GetExecuteReader(); List <CategoriesModel> categoriesList = new List <CategoriesModel>(); while (sqlDataReader.Read()) { CategoriesModel categoriesModel = new CategoriesModel(); categoriesModel.CategoryId = Convert.ToInt32(sqlDataReader["CategoryId"]); categoriesModel.Name = sqlDataReader["Name"].ToString(); categoriesModel.Description = sqlDataReader["Description"].ToString(); categoriesList.Add(categoriesModel); } return(categoriesList); } catch (SqlException ex) { throw new System.Exception(ex.Message); } finally { CloseSqlConnection(); } }
public CategoriesModel getCategoryByName(string name) { try { OpenSqlConnection(); SqlCommand sqlCommand = CreateCommandSc("GetCategoryByName"); sqlCommand.Parameters.Add(new SqlParameter("@Name", name)); SqlDataReader sqlDataReader = GetExecuteReader(); CategoriesModel categoriesModel = new CategoriesModel(); while (sqlDataReader.Read()) { categoriesModel.CategoryId = Convert.ToInt32(sqlDataReader["CategoryId"]); categoriesModel.Name = sqlDataReader["Name"].ToString(); categoriesModel.Description = sqlDataReader["Description"].ToString(); } return(categoriesModel); } catch (SqlException ex) { throw new System.Exception(ex.Message); } finally { CloseSqlConnection(); } }
public void AddCategories(CategoriesModel _CategoriesModel) { _CategoriesModel.CategoryID = (short)((int)(from S in CategoriesData.Descendants("Category") orderby(short) S.Element("CategoryID") descending select(short) S.Element("CategoryID")).FirstOrDefault() + 1); CategoriesData.Root.Add(new XElement("Category", new XElement("CategoryID", _CategoriesModel.CategoryID), new XElement("CategoryNameTxt", _CategoriesModel.CategoryNameTxt))); CategoriesData.Save(HttpContext.Current.Server.MapPath("~/App_Data/categories.xml")); }
public IActionResult Index() { //MoviesModel model = new MoviesModel(); CategoriesModel model = new CategoriesModel(); model.Movies = manager.GetComingSoonMovies(); return(View(model)); }