public bool UpdateCategoryById(CategoryInput categoryInput, out string msg) { IQueryable <Categorylnfo> categorylnfos = _dbContext.Set <Categorylnfo>(); Categorylnfo categorylnfo = categorylnfos.Where(c => c.CategoryId == categoryInput.CategoryId).FirstOrDefault(); if (categorylnfo != null) { try { Categorylnfo categorylnfo1 = categorylnfos.Where(c => c.CategoryName == categoryInput.CategoryName).FirstOrDefault(); if (categorylnfo1 == null || categoryInput.CategoryName == categorylnfo.CategoryName) { categorylnfo.CategoryName = categoryInput.CategoryName; categorylnfo.CurrentPrice = categoryInput.CurrentPrice; if (_dbContext.SaveChanges() > 0) { msg = "修改成功!"; return(true); } msg = "错误!内部出现异常!"; return(false); } msg = "该类名已存在!"; return(false); } catch (Exception ex) { msg = ex.Message; return(false); } } msg = "找不到该类目数据!数据可能被篡改!"; return(false); }
public JsonResult Update(CategoryInput categoryInput) { string msg; _categoryManageService.UpdateCategoryById(categoryInput, out msg); return(Json(msg)); }
public async Task <IActionResult> Post([FromBody] CategoryInput model) { if (ModelState.IsValid) { var category = this.unitOfWork.CategoriesRepository.GetByName(model.Name); if (category == null) { category = new Category { Name = model.Name }; this.unitOfWork.CategoriesRepository.Add(category); await this.unitOfWork.Save(); return(Created("CategoryPost", new { Id = category.CategoryId })); } else { ModelState.AddModelError("exists", "A category with the name you entered already exists"); return(UnprocessableEntity(ModelState)); } } else { return(UnprocessableEntity(ModelState)); } }
public async Task AddEditCategory(CategoryInput input) { var id = await _categoryManager.AddEditCategory(input.Name.Sluggify(), input.Name); var categoryCreated = _categoryRepository.FirstOrDefault(id); foreach (var inputLanguageInput in input.LanguageInputs) { if (string.IsNullOrEmpty(inputLanguageInput.Text)) { continue; } var foundWithSameLanguage = _categoryContentRepository.FirstOrDefault( a => a.CategoryId == id && a.Lang == inputLanguageInput.Lang); if (foundWithSameLanguage == null) { await _categoryManager.AddEditCategoryContent( CategoryContent.CreateCategoryContent(inputLanguageInput.Lang, inputLanguageInput.Text, categoryCreated)); } else { foundWithSameLanguage.DisplayText = inputLanguageInput.Text; await _categoryManager.AddEditCategoryContent(foundWithSameLanguage); } } }
public CategoryInput getModel() { var model = new CategoryInput(); Mapper.CreateMap <CategoryInputView, CategoryInput>(); Mapper.Map <CategoryInputView, CategoryInput>(this, model); return(model); }
public CategoryInput getModel() { var model = new CategoryInput(); Mapper.CreateMap<CategoryInputView, CategoryInput>(); Mapper.Map<CategoryInputView, CategoryInput>(this, model); return model; }
public Category Add([FromBody] CategoryInput category) { var entity = new Category() { Name = category.Name, ParentCategoryId = category.ParentCategoryId, IsActive = category.IsActive }; return(_repository.Create(entity)); }
public async Task <Category> Add(CategoryInput category) { var entity = mapper.MapCategory(category, new CategoryEntity()); this.dbContext.Add(entity); await SaveChanges(); return(mapper.MapCategory(entity, new Category())); }
public Category Update(int id, [FromBody] CategoryInput category) { var entity = new Category() { Id = id, Name = category.Name, ParentCategoryId = category.ParentCategoryId, IsActive = category.IsActive }; return(_repository.Update(entity)); }
public ActionResult Create(CategoryInput categoryInput) { if (!ModelState.IsValid) return View(categoryInput); var category = mappingEngine.Map<CategoryInput, Category>(categoryInput); repository.Save(category); return RedirectToAction("Index"); }
public ActionResult Create(CategoryInput input) { if (!ModelState.IsValid) { return(View(input)); } Db.Insert(new Category { Name = input.Name }); return(Json(new {})); }
public JsonResult AddCategory(CategoryInput categoryInput) { string msg; if (categoryInput.CurrentPrice == null) { msg = "你输入的不是数字噢!检查一下吧!"; return(Json(msg)); } _categoryManageService.AddCategory(categoryInput, out msg); return(Json(msg)); }
protected void categorySaveButton_OnClick(object sender, EventArgs e) { CategoryInput input = new CategoryInput(); input.Name = CategoryInputTextBox.Text; string message = maneger.Save(input); output.Text = message; CategorySetupGridView.DataSource = maneger.GetAllCategory(); CategorySetupGridView.DataBind(); }
public async Task <Category> Update(Guid categoryId, CategoryInput category) { var entity = await this.Entity(categoryId); if (entity != null) { mapper.MapCategory(category, entity); await SaveChanges(); return(mapper.MapCategory(entity, new Category())); } throw new KeyNotFoundException($"Cannot find category {categoryId.ToString()}"); }
public string UpdateById(CategoryInput input) { int rowAffect = categoryGateway.UpdateById(input); if (rowAffect > 0) { return("Update Successful"); } else { return("Update Failed"); } }
public int UpdateById(CategoryInput input) { string query = "Update Category SET Name = @categoryName WHERE Id = @id"; command = new SqlCommand(query, connection); command.Parameters.AddWithValue("@id", input.ID); command.Parameters.AddWithValue("@categoryName", input.Name); connection.Open(); int rowAffect = command.ExecuteNonQuery(); connection.Close(); return(rowAffect); }
public async Task Add(CategoryInput categoryInput) { //var userId = ExtensionMethod.GetUserId(_httpContextAccessor.HttpContext); //if (userId == null) //{ // throw new ArgumentNullException("userId invalied"); //} var category = new Category { Name = categoryInput.Name, CreationTime = DateTime.Now, // CreatorUserId = userId }; await _asyncRepository.AddAsync(category); }
public int Save(CategoryInput input) { string query = "INSERT INTO Category(Name)" + " VALUES(@categoryName)"; command = new SqlCommand(query, connection); command.Parameters.AddWithValue("@categoryName", input.Name); connection.Open(); int rowAffect = command.ExecuteNonQuery(); connection.Close(); return(rowAffect); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { int id = Convert.ToInt32(Request.QueryString["Id"]); //Response.Write(id); //ID. = id); CategoryInput input = maneger.GetCategoryById(id); if (input != null) { idHiddenField.Value = input.ID.ToString(); CategoryInputTextBox.Text = input.Name; } } }
protected void categoryUpdateButton_Click(object sender, EventArgs e) { CategoryInput aInput = new CategoryInput(); aInput.ID = Convert.ToInt32(idHiddenField.Value); if (CategoryInputTextBox.Text != "") { aInput.Name = CategoryInputTextBox.Text; maneger.UpdateById(aInput); Response.Redirect("CategorySetupUI.aspx"); } else { string message = "Enter data perfectly!"; outputLabel.Text = message; //Response.Write("Enter data perfectly!"); } }
public string Save(CategoryInput input) { if (categoryGateway.IsExists(input.Name) || (categoryGateway.IsEmpty(input.Name))) { return("This Category Type is Already Exists Or Type cant be empty"); } else { int rowAffect = categoryGateway.Save(input); if (rowAffect > 0) { return("Save Successful"); } else { return("Save Failed"); } } }
public bool AddCategory(CategoryInput categoryInput, out string msg) { IQueryable <Categorylnfo> categorylnfos = _dbContext.Set <Categorylnfo>(); Categorylnfo categorylnfo = categorylnfos.Where(c => c.CategoryId == categoryInput.CategoryId).FirstOrDefault(); if (categorylnfo == null) { Categorylnfo categorylnfo1 = categorylnfos.Where(c => c.CategoryName == categoryInput.CategoryName).FirstOrDefault(); if (categorylnfo1 == null) { try { Categorylnfo newCategory = new Categorylnfo { CategoryId = categoryInput.CategoryId, CategoryName = categoryInput.CategoryName, CurrentPrice = categoryInput.CurrentPrice, Unit = categoryInput.Unit, DelFlag = false, AddTime = DateTime.Now }; _dbContext.Set <Categorylnfo>().Add(newCategory); if (_dbContext.SaveChanges() > 0) { msg = "添加成功!"; return(true); } msg = "失败!内部出现异常!"; return(false); } catch (Exception ex) { msg = ex.Message; return(false); } } msg = "该类名已存在!"; return(false); } msg = "类目编号已存在!"; return(false); }
/// <summary> /// /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task AddCategoryAsync(CategoryInput input) { var category = input.MapTo <Category>(); if (input.Id.HasValue) { category = _categoryRepository.Get(input.Id.Value); category.Description = input.Description; category.Name = input.Name; category.Sort = input.Sort; FileRelationRepository.Delete(x => x.KeyId == input.Id && x.ModuleId == ModuleType.Category); } else { await _categoryRepository.InsertAsync(category); CurrentUnitOfWork.SaveChanges(); } // await AddFileRelationAsync(input.FileId, category.Id, ModuleType.Category); }
public CategoryOutput Create(CategoryInput input) { var category = new Category { Localized = input.Localized.Select(i => new LocalizedCategory { LanguageCode = i.LanguageCode, Name = i.Name, Description = i.Description }).ToList() }; using (var dbContext = new AllureContext()) { dbContext.Set <Category>().Add(category); dbContext.SaveChanges(); } return(Id(category.Id)); }
public async Task <IActionResult> Put(short id, [FromBody] CategoryInput model) { if (ModelState.IsValid) { var category = this.unitOfWork.CategoriesRepository.GetById(id); if (category == null) { return(NotFound()); } else { category.Name = model.Name; this.unitOfWork.CategoriesRepository.Update(category); await this.unitOfWork.Save(); return(NoContent()); } } return(UnprocessableEntity()); }
public List <CategoryInput> GetAllCategory() { string query = "SELECT * FROM Category"; command = new SqlCommand(query, connection); connection.Open(); reader = command.ExecuteReader(); List <CategoryInput> categoryList = new List <CategoryInput>(); while (reader.Read()) { CategoryInput input = new CategoryInput(); input.ID = Convert.ToInt32(reader["Id"]); input.Name = reader["Name"].ToString(); categoryList.Add(input); } reader.Close(); connection.Close(); return(categoryList); }
public CategoryInput GetCategoryById(int id) { string query = "SELECT * FROM Category WHERE Id=@id"; command = new SqlCommand(query, connection); command.Parameters.AddWithValue("@id", id); connection.Open(); reader = command.ExecuteReader(); reader.Read(); CategoryInput input = new CategoryInput(); if (reader.HasRows) { //CategoryInput input = new CategoryInput(); input.ID = Convert.ToInt32(reader["ID"]); input.Name = reader["Name"].ToString(); } reader.Close(); connection.Close(); return(input); }
public CategoryOutput Update(CategoryInput input) { var category = new Category { Id = input.Id, Localized = input.Localized .Select(c => new LocalizedCategory { CategoryId = input.Id, LanguageCode = c.LanguageCode, Name = c.Name, Description = c.Description }).ToList() }; using (var dbContext = new AllureContext()) { dbContext.UpdateGraph(category, m => m.OwnedCollection(c => c.Localized)); dbContext.SaveChanges(); } return(Id(category.Id)); }
public ActionResult Create(CategoryInput category) { if (ModelState.IsValid) { category.Name = category.Name.ToUpper(); var newCategory = Mapper.Map <Category>(category); Data.Categories.Add(newCategory); try { Data.SaveChanges(); TempData["message"] = "Category successfully added"; TempData["color"] = "alert-success"; return(RedirectToAction("Index")); } catch (Exception) { ModelState.AddModelError("", "An error occurred. Maybe category with that name already exists. Try different name"); return(View(category)); } } return(View(category)); }
public CategoryInputView(CategoryInput model) { Mapper.CreateMap<CategoryInput, CategoryInputView>(); Mapper.Map<CategoryInput, CategoryInputView>(model, this); }
public CategoryInput createCategoryInput(CategoryInput model) { db.categoryInputs.Add(model); db.SaveChanges(); return(model); }
public async Task <Category> Update(Guid categoryId, [FromBody] CategoryInput category) { return(await repo.Update(categoryId, category)); }
public async Task <Category> Add([FromBody] CategoryInput category) { return(await repo.Add(category)); }
public CategoryInput createCategoryInput(CategoryInput model) { db.categoryInputs.Add(model); db.SaveChanges(); return model; }