// PUT: api/Categories/ public async Task<IHttpActionResult> PutCategories(Category category) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (category == null) { return NotFound(); } try { await categoryRepo.EditAsync(category); return Ok("Category Updated"); } catch (Exception ex) { if (!CategoryExists(category.CategoryId)) { return NotFound(); } else { throw ex; } } }
public static CategoryCompositeViewModel ConvertCategoryToViewModel(Category category) { CategoryCompositeViewModel categoryCompositeViewModel = new CategoryCompositeViewModel() { CategoryId = category.CategoryId, text = category.Name, Prefix = category.Prefix, type = "category", IdParentCategory = category.IdParentCategory, IdTranslationName = category.IdTranslationName, Image = category.Image, IsFinal = category.IsFinal, IsFirst = category.IsFirst, Name = category.Name, Orden = category.Orden, Comment = category.Comment, Pending = category.Pending, Active = category.Active, nextsibling = "category", Translation = category.Translation }; return categoryCompositeViewModel; }
public static Category CreateModel(CategoryViewModel categoryViewModel) { Category category = new Category() { Active = categoryViewModel.CategoryActive, Name = categoryViewModel.Name, IdParentCategory = categoryViewModel.IdParentCategory, Orden = categoryViewModel.Orden, Image = categoryViewModel.Image, Pending = categoryViewModel.Pending, Prefix = categoryViewModel.Prefix, Comment = categoryViewModel.Comment, IsFinal = categoryViewModel.IsFinal, IsFirst = categoryViewModel.IsFirst }; category.Translation = new Translation() { Spanish = categoryViewModel.Spanish, English = categoryViewModel.English, French = categoryViewModel.French, German = categoryViewModel.German, Language5 = categoryViewModel.Language5, Language6 = categoryViewModel.Language6, Language7 = categoryViewModel.Language7, Language8 = categoryViewModel.Language8, Active = categoryViewModel.TranslationActive, }; category.TranslationDescription = new Translation() { Spanish = categoryViewModel.SpanishDesc, English = categoryViewModel.EnglishDesc, French = categoryViewModel.FrenchDesc, German = categoryViewModel.GermanDesc, Language5 = categoryViewModel.LanguageDesc5, Language6 = categoryViewModel.LanguageDesc6, Language7 = categoryViewModel.LanguageDesc7, Language8 = categoryViewModel.LanguageDesc8, Active = categoryViewModel.TranslationActiveDesc, }; category.Modules = new List<Module>(); category.Modules.Add(new Module() { ModuleId = categoryViewModel.ModuleId, Name = categoryViewModel.ModuleName }); return category; }