コード例 #1
0
ファイル: CategoryMapper.cs プロジェクト: jcvaldes/MyRoomV7
        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;
        }
コード例 #2
0
        // POST: api/Categories/products

        //[Route("products")]
        //[HttpPost]
        //public IHttpActionResult PostCategoriesWithProducts(ICollection<Category> categories)
        //{
        //    if (!ModelState.IsValid)
        //    {
        //        return BadRequest(ModelState);
        //    }

        //    try
        //    {
        //        CategoryProductRepository categpryProductRepo = new CategoryProductRepository(new MyRoomDbContext());
              
        //        categpryProductRepo.InsertCategoryProduct(categories.ToList());

        //        return Ok("Category Product Inserted");
        //    }
        //    catch (Exception ex)
        //    {
        //        throw ex;
        //    }
        //}
        // POST: api/Categories
        public IHttpActionResult PostCategories(CategoryViewModel categoryViewModel)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            try
            {
                //if (category.Modules != null)
                //{ 
                //    categoryRepo.Update(category);
                //} 
                Category category = CategoryMapper.CreateModel(categoryViewModel);
                categoryRepo.ModuleStateUnchange(category);
                 
                if (!category.IsFirst)
                {
                    category.Modules = null;
                }

                categoryRepo.Insert(category);

                //busco hotel con el catalogo seleccionado
                ActiveHotelCatalogRepository hotelCatalog = new ActiveHotelCatalogRepository(new MyRoomDbContext());
                int hotelId = hotelCatalog.GetByCatalogId(categoryViewModel.CatalogId);
                if (hotelId > 0)
                { 
                    //inserto categorias a hotel relacionado
                    ActiveHotelCategoryRepository activeHotelCategoryRepo = new ActiveHotelCategoryRepository(new MyRoomDbContext());
                    List<ActiveHotelCategory> hotelscategories = new List<ActiveHotelCategory>();
                    hotelscategories.Add(new ActiveHotelCategory() { IdCategory = category.CategoryId, IdHotel = hotelId });
                    activeHotelCategoryRepo.InsertActiveHotelCategory(hotelscategories, hotelId, true);
                }
                return Ok(category);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }