public void Update(CategoryJson categoryJson) { var categoryToUpdate = db.Categories.Where(c => c.Id == categoryJson.id).SingleOrDefault(); AssignValue(categoryJson, categoryToUpdate); db.SaveChanges(); }
public HttpResponseMessage Update(CategoryJson categoryJson) { if (categoryJson.Id == null) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Parameter 'Id' cannot be null")); } Category category = Repository.CategoryRepository.FindById(categoryJson.Id.Value); if (category == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Category with id '" + category.Id.Value + "' not found!")); } category.Name = categoryJson.Name; if (!string.IsNullOrEmpty(categoryJson.ImageData)) { byte[] imageData = Convert.FromBase64String(categoryJson.ImageData); string subPath = "photos/category/" + categoryJson.Id + "." + categoryJson.ImageType; string imagePath = HttpContext.Current.Server.MapPath("~/" + subPath); File.WriteAllBytes(imagePath, imageData); category.ImageUrlRelative = subPath; } category = Repository.CategoryRepository.Update(category); return(Request.CreateResponse(HttpStatusCode.OK, category)); }
public void Post(CategoryJson categoryJson) { Repository <Category> categoryRepository = new Repository <Category>(db); var category = convertor.CategoryJsonToCategory(categoryJson); categoryRepository.Insert(category); db.SaveChanges(); }
private CategoryJson toCategoryJson() { CategoryJson categoryJson = new CategoryJson(); categoryJson.Id = this.Id.ToString(); categoryJson.Text = this.Name; categoryJson.Childs = arrayToCategoryJson(this.subCategories); return(categoryJson); }
public Category CategoryJsonToCategory(CategoryJson categoryJson) { return(new Category() { Id = categoryJson.id, Name = categoryJson.name, ParentCategoryId = categoryJson.parentCategoryId }); }
public CategoryJson ConvertASingleCategoryToASingleCategoryJson(Category category) { var categoryJson = new CategoryJson() { id = category.Id, name = category.Name, subCategories = new List <Category>() }; return(categoryJson); }
public JsonResult GetSubCategories(CategoryJson categoryJson) { var model = EconomyBusiness.GetSubCategoriesByCategory(categoryJson.CategoryId).ToList(); var list = JsonConvert.SerializeObject(model, Formatting.Indented, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); return(Json(list, JsonRequestBehavior.DenyGet)); }
public HttpResponseMessage Create(CategoryJson categoryJson) { var category = new Category { Name = categoryJson.Name }; category = Repository.CategoryRepository.Add(category); byte[] imageData = Convert.FromBase64String(categoryJson.ImageData); string subPath = "photos/category/" + category.Id + "." + categoryJson.ImageType; string imagePath = HttpContext.Current.Server.MapPath("~/" + subPath); File.WriteAllBytes(imagePath, imageData); category.ImageUrlRelative = subPath; category = Repository.CategoryRepository.Update(category); return(Request.CreateResponse(HttpStatusCode.OK, category)); }
public List <CategoryJson> ConvertCategoryToCategoryJson(List <Category> categories) { var categoryJsonList = new List <CategoryJson>(); foreach (var cat in categories) { var categoryJson = new CategoryJson() { id = cat.Id, name = cat.Name, subCategories = GetSubCategories(cat) }; categoryJsonList.Add(categoryJson); } return(categoryJsonList); }
/// <summary> /// Recursive method to set category ordering /// </summary> /// <param name="json"></param> public async Task SetCategoryOrdering(int parent, CategoryJson[] json) { int sortOrder = 0; foreach (var item in json) { var category = await _categoryService.FindAsync(item.id); category.Parent = parent; category.Ordering = sortOrder; category.ObjectState = Repository.Pattern.Infrastructure.ObjectState.Modified; _categoryService.Update(category); sortOrder++; if (item.children != null) { await SetCategoryOrdering(item.id, item.children); } } }
private void AssignValue(CategoryJson categoryJson, Category categoryToUpdate) { categoryToUpdate.Name = categoryJson.name; categoryToUpdate.ParentCategoryId = categoryJson.parentCategoryId; }
// PUT: api/Category/5 public void Put(CategoryJson categoryJson) { categoryLogic.Update(categoryJson); }
// POST: api/Category public void Post(CategoryJson categoryJson) { categoryLogic.Post(categoryJson); }