public bool CategoryUpdateName(CategoryUpdate updateCatgObj) { CategoryUpdateRipository catgUpdRipoObj = new CategoryUpdateRipository(); bool updateCatgInfo = catgUpdRipoObj.CategoryUpdateName(updateCatgObj); return(updateCatgInfo); }
public async Task <bool> UpdateCategoryAsync( Guid categoryId, CategoryUpdate category, CancellationToken ct ) { var entity = await _dbContext.Categories.FirstOrDefaultAsync(x => x.Id == categoryId); if (entity == null) { return(false); } if (category.Color != null) { entity.Color = category.Color; } if (category.Name != null) { entity.Name = category.Name; } _dbContext.Update(entity); var result = await _dbContext.SaveChangesAsync(ct); if (result >= 1) { return(true); } else { return(false); } }
public async Task <IActionResult> Update([FromBody] CategoryUpdate data) { BaseAPIModel <ProductCategory> response = new BaseAPIModel <ProductCategory>(); response.status = false; response.request = "Update Product Categories"; try { ProductCategory category = new ProductCategory { ID = data.ID, Name = data.Name, Description = data.Description, IsActive = true, RegistedDate = DateTime.Now }; _context.ProductCategories.Update(category); await _context.SaveChangesAsync(); response.status = true; return(Ok(response)); } catch (Exception ex) { response.error = ex.InnerException.Message; return(BadRequest(response)); } }
public void Update(CategoryUpdate categoryUpdate) { var category = _categoryRepo.Find(categoryUpdate.Id); category.Code = categoryUpdate.Code; category.Description = categoryUpdate.Description; category.Name = categoryUpdate.Name; category.Permalink = categoryUpdate.Permalink; category.Published = categoryUpdate.Published; category.ListImageCaption = categoryUpdate.ListImageCaption; category.ListImageURL = categoryUpdate.ListImageURL; category.ListImageAltText = categoryUpdate.ListImageAltText; category.SliderImageURL = categoryUpdate.SliderImageURL; category.SliderImageAltText = categoryUpdate.SliderImageAltText; category.SliderImageCaption = categoryUpdate.SliderImageCaption; SEOTool SEOTool = null; if (category.SEOTools != null && category.SEOTools.Count() > 0) { SEOTool = category.SEOTools.First(); } else { SEOTool = new Core.Domain.SEOTool(); category.SEOTools = new List <Core.Domain.SEOTool>(); category.SEOTools.Add(SEOTool); } SEOTool.FocusKeyword = categoryUpdate.FocusKeyword; SEOTool.MetaDescription = categoryUpdate.MetaDescription; SEOTool.SEOTitle = categoryUpdate.SEOTitle; _categoryRepo.Update(category); }
public bool CategoryUpdateName(CategoryUpdate updateCatgObj) { string connectionString = @"Server=DESKTOP-063GM06\SQLEXPRESS;Database=STOCKMANAGEMENTSYSTEM;Integrated Security=true"; string query = @"SELECT Name FROM Categories WHERE Name='" + updateCatgObj.CategoryUpdateName + "'"; SqlConnection conn = new SqlConnection(connectionString); SqlCommand comd = new SqlCommand(query, conn); conn.Open(); SqlDataReader dr = comd.ExecuteReader(); if (dr.HasRows) { dr.Close(); conn.Close(); return(false); } dr.Close(); query = @"UPDATE Categories SET Name='" + updateCatgObj.CategoryUpdateName + "'WHERE Name='" + updateCatgObj.CategoryPreviousName + "'"; comd = new SqlCommand(query, conn); comd.ExecuteNonQuery(); conn.Close(); return(true); }
public IActionResult Put(int id, [FromBody] CategoryUpdate category) { category.Id = id; var categoryResponse = _categoryService.Update(category); return(categoryResponse.ToJsonResult()); }
public static AbstractEntities.CategoryUpdate ToAbstract(this CategoryUpdate web) { if (web == null) { return(null); } return(new AbstractEntities.CategoryUpdate(web.Id, web.Name)); }
public IActionResult Put(int id, [FromBody] CategoryUpdate category) { var responce = new ServiceResponse <CategoryUpdate> { Response = category }; var categoryResponse = _categoryManager.Update(id, responce); return(categoryResponse.ToJsonResult()); }
public async Task <IHttpActionResult> PutCategory(long id, CategoryUpdate categoryIn) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (categoryIn.IsActive != 0) { if (categoryIn.IsActive != 1) { return(ResponseMessage(getHttpResponse(HttpStatusCode.BadRequest))); } } Category categoryCurrent = await db.Categories.FindAsync(id); if (categoryCurrent == null) { return(ResponseMessage(getHttpResponse(HttpStatusCode.NotFound))); } if (categoryCurrent.Title != categoryIn.Title) { if (CategoryTitleExists(categoryIn.Title)) { return(ResponseMessage(getHttpResponse(HttpStatusCode.Conflict))); } } categoryCurrent.Title = (categoryIn.Title != null) ? categoryIn.Title : categoryCurrent.Title; categoryCurrent.Description = (categoryIn.Description != null) ? categoryIn.Description : categoryCurrent.Description; categoryCurrent.UpdatedAt = DateTime.Now; categoryCurrent.IsActive = categoryIn.IsActive; categoryCurrent.Image = (categoryIn.imageUrl != null) ? categoryIn.imageUrl : categoryCurrent.Image; db.Entry(categoryCurrent).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CategoryExists(id)) { return(ResponseMessage(getHttpResponse(HttpStatusCode.NotFound))); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public void Update_WhenRecordDoesNotExist_ShouldThrow() { using (var dataLayer = DataLayerHelper.CreateDataLayer()) using (var controller = new CategoriesController(dataLayer)) { var categoryUpdate = new CategoryUpdate { Id = 1, Name = "Cinemae" }; controller.Update(categoryUpdate); } }
// GET: Category/Update public ActionResult Edit(int id) { var service = CreateCategoryService(); var detail = service.GetCategoryById(id); var model = new CategoryUpdate { CategoryId = detail.CategoryId, CategoryName = detail.CategoryName }; return(View(model)); }
public async Task <dynamic> Update([FromBody] CategoryUpdate item) { if (item == null) { return new { JsonString = "Error" } } ; var currentUser = JwtIdentity.UserInfo(Thread.CurrentPrincipal.Identity); //item.SubmiterUserId = currentUser.Id; var result = await _sqlData.Category.Update(item); return(new { Result = JsonConvert.DeserializeObject(result) }); }
public async Task <IActionResult> UpdateCategoryAsync( Guid categoryId, [FromBody] CategoryUpdate form, CancellationToken ct) { var task = await _repository.UpdateCategoryAsync(categoryId, form, ct); if (task == false) { return(NotFound()); } return(Accepted()); }
public ActionResult Edit(CategoryUpdate model) { if (!ModelState.IsValid) { return(View(model)); } var service = new CategoryServices(); if (!service.UpdateCategory(model)) { return(View(model)); } return(RedirectToAction(nameof(Index))); }
public IActionResult Update([FromBody] CategoryUpdate updatedCategory) { if (updatedCategory == null) { throw new InvalidRequestArgumentException("The category cannot be null or empty."); } if (string.IsNullOrWhiteSpace(updatedCategory.Name)) { throw new InvalidRequestArgumentException("Category name cannot be null or empty."); } dataLayer.UpdateCategory(updatedCategory.ToAbstract()); return(NoContent()); }
public bool UpdateCategory(CategoryUpdate model) { using (var context = new ApplicationDbContext()) { var entity = context .Categories .Single(j => j.CategoryId == model.CategoryId); entity.CategoryId = model.CategoryId; entity.CategoryName = model.CategoryName; entity.CategoryDescription = model.CategoryDescription; return(context.SaveChanges() == 1); } }
public bool UpdateCategory(CategoryUpdate model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Categories .Single(e => e.CategoryId == model.CategoryId); entity.CategoryName = model.CategoryName; bool success = true; try { ctx.SaveChanges(); } catch { success = false; } return(success); } }
public IActionResult Put(int id, [FromBody] CategoryUpdate categoryUpdate) { var category = Service.Get(id); if (category == null) { return(NotFound()); } category.Name = categoryUpdate.Name; category.Description = categoryUpdate.Description; category.Tags = categoryUpdate.Tags; Service.Update(category); return(Ok(category)); }
public async Task ValidateUpdateModel(CategoryUpdate model) { if (model == null) { throw new ValidationFailedException("No data provided to perform update"); } if (model.Id <= 0) { throw new ValidationFailedException("Must specify word id"); } if (string.IsNullOrEmpty(model.Name)) { throw new ValidationFailedException("Word must have a value"); } if (await WordValueExists(model.Id, model.Id, model.Name)) { throw new ValidationFailedException("Word already exists"); } }
private void btnKategoriGuncelle_Click(object sender, EventArgs e) { CategoryUpdate cGuncelle = new CategoryUpdate(); try { Category category = new Category() { CategoryID = Convert.ToInt32(dGvKategoriler.SelectedRows[0].Cells[0].Value), CategoryName = dGvKategoriler.SelectedRows[0].Cells[1].Value.ToString(), Description = dGvKategoriler.SelectedRows[0].Cells[2].Value.ToString() }; cGuncelle.category = category; cGuncelle.Show(); } catch (Exception ex) { MessageBox.Show("Lütfen Kategori Listesini 'Kategoriler' Sekmesinden Listeleyiniz...\n\n" + ex.Message); } }
public HttpResponseMessage Update(Int32 id, [FromBody] CategoryUpdate model) { Category category = null; try { category = this.categoryService.Read(id); } catch (PermissionException) { return(this.Request.CreateResponse(HttpStatusCode.Forbidden)); } if (category == null) { return(this.Request.CreateErrorResponse(HttpStatusCode.NotFound, String.Format("Could not locate category with id {0}", id))); } category.Name = model.Name; category.Description = model.Description; category.SortOrder = model.SortOrder; category = this.categoryService.Update(category); return(this.Request.CreateResponse <CategoryRead>(category.ToModel())); }
public async Task <CategoryUpdateResult> UpdateCategory(CategoryUpdate model) { await validator.ValidateUpdateModel(model); var toUpdate = await context.Categories.SingleOrDefaultAsync(x => x.Id == model.Id); if (toUpdate == null) { throw new ArgumentException($"Can't fine category with id {model.Id}"); } toUpdate = mapper.MapCategory(toUpdate, model); await context.SaveChangesAsync(); var categoryModel = await categoryProvider.GetCategory(model.Id); return(new CategoryUpdateResult() { Category = categoryModel }); }
public ActionResult Edit(int?id) { if (id == null) { return(RedirectToAction("Index")); } var service = new CategoryServices(); if (service.GetById((int)id) == null) { return(View()); } var detail = service.GetById((int)id); var model = new CategoryUpdate { CategoryId = detail.CategoryId, CategoryName = detail.CategoryName, CategoryDescription = detail.CategoryDescription }; return(View(model)); }
public void Add(CategoryUpdate categoryUpdate) { var category = new Category { Code = categoryUpdate.Code, Description = categoryUpdate.Description, Name = categoryUpdate.Name, Permalink = categoryUpdate.Permalink, Published = categoryUpdate.Published, ListImageCaption = categoryUpdate.ListImageCaption, ListImageURL = categoryUpdate.ListImageURL, ListImageAltText = categoryUpdate.ListImageAltText, SliderImageURL = categoryUpdate.SliderImageURL, SliderImageAltText = categoryUpdate.SliderImageAltText, SliderImageCaption = categoryUpdate.SliderImageCaption }; SEOTool SEOTool = null; if (category.SEOTools != null && category.SEOTools.Count() > 0) { SEOTool = category.SEOTools.First(); } else { SEOTool = new Core.Domain.SEOTool(); category.SEOTools = new List <Core.Domain.SEOTool>(); category.SEOTools.Add(SEOTool); } SEOTool.FocusKeyword = categoryUpdate.FocusKeyword; SEOTool.MetaDescription = categoryUpdate.MetaDescription; SEOTool.SEOTitle = categoryUpdate.SEOTitle; _categoryRepo.Add(category); }
public ServiceResponse Update(CategoryUpdate request) { var serviceResponse = new ServiceResponse(); try { if (request == null) { serviceResponse.Errors.Add("Request", "Should not be null"); } var category = _unitOfWork.CategoryRepository.GetById(request.Id); if (category == null) { serviceResponse.Errors.Add(nameof(request.Id), $"Category with Id = {request.Id} doesnt exsits"); serviceResponse.StatusCode = 400; } if (serviceResponse.IsSuccess) { category = _mapper.Map <Models.DAO.Category>(request); _unitOfWork.CategoryRepository.Update(category); _unitOfWork.Save(); _logger.LogDebug("Successfully got data from db"); serviceResponse.StatusCode = 204; } } catch (Exception ex) { _logger.LogError(ex.Message); serviceResponse.Errors.Add("Request", $"AAAAAAAAAAAA, WHAT HAPPENED??!?!?!?!??"); serviceResponse.StatusCode = 500; } return(serviceResponse); }
public ActionResult Edit(int id, CategoryUpdate model) { if (!ModelState.IsValid) { return(View(model)); } if (model.CategoryId != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = CreateCategoryService(); if (service.UpdateCategory(model)) { TempData["SaveResult"] = $"'{model.CategoryName}' was updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", $"'{model.CategoryName}' could not be updated."); return(View(model)); }
public async Task <TMapTo> UpdateCategoryAsync <TMapTo>(CategoryUpdate categoryUpdate) where TMapTo : Category { try { if (categoryUpdate is null) { throw new ArgumentNullException("categoryUpdate"); } var dbCategories = await _categoriesContext.Categories .Where(dc => dc.CategoryId == categoryUpdate.CategoryId).ToArrayAsync(); if (dbCategories[0] is null) { throw new IdNotFoundException($"Category with id {categoryUpdate.CategoryId} was not found"); } if (dbCategories.Length > 1) { throw new DuplicatesFoundException( $"Found more than one category with id {categoryUpdate.CategoryId}"); } var updatedDbCategory = _mapper.Map(categoryUpdate, dbCategories[0], typeof(CategoryUpdate), typeof(Categories)); var result = await _categoriesContext.SaveChangesAsync(); var mappedUpdatedCategory = _mapper.Map <Categories, TMapTo>(updatedDbCategory as Categories); return(mappedUpdatedCategory); } catch (Exception ex) { throw new UpdateOperationException("Update operation for categories failed.", ex); } }
public async Task<CategoryUpdate.response> CategoryUpdate(CategoryUpdate.request request, CancellationToken? token = null) { return await SendAsync<CategoryUpdate.response>(request.ToXmlString(), token.GetValueOrDefault(CancellationToken.None)); }
internal void OnCategoryUpdate(object sender, ChannelEventArgs e) { CategoryUpdate?.Invoke(sender, e.Convert <ChannelCategory>()); }
public async Task <IActionResult> UpdateInsertCategory([FromBody] CategoryUpdate categoryUpdate) { try { if (categoryUpdate.CategoryId == null || categoryUpdate.CategoryId == Guid.Empty) { Guid categoryId; if (categoryUpdate.CategoryName.Length > 0) { var categoryNew = new Category(); var insertCategory = _mapper.Map(categoryUpdate, categoryNew); await _uow.Repository <Category>().AddAsync(insertCategory); await _uow.SaveChangesAsync(); categoryId = insertCategory.CategoryId; } else { return(BadRequest(new { error = $"The category field cannot be empty. The category was not added." })); } if (categoryId != Guid.Empty) { return(Ok(new { info = "The new category has been added." })); } return(BadRequest(new { error = $"Something went wrong, the category \'{categoryUpdate.CategoryName}\' was not added." })); } var category = await _uow.Repository <Category>() .GetAll().FirstOrDefaultAsync(x => x.CategoryId == categoryUpdate.CategoryId); if (category == null) { return(BadRequest( new { error = $"The category with ID: {categoryUpdate.CategoryId} is unavailable." })); } if (categoryUpdate.CategoryName.Length > 0) { categoryUpdate.Picture = category.Picture; _mapper.Map(categoryUpdate, category); await _uow.SaveChangesAsync(); return(Ok(new { info = "The category has been updated." })); } return(BadRequest(new { error = $"The category field cannot be empty. The category was not added." })); } catch (Exception e) { return(Problem(e.Message, null, null, e.Source)); } }
public Category MapCategory(Category category, CategoryUpdate model) { category.Name = model.Name; return(category); }