public IActionResult CreateFavorite(CreateFavoriteModelWithCategories model) { try { //creates coordinates for the favorite var coordToCreate = new Coordinates(); coordToCreate.Latitude = model.Latitude; coordToCreate.Longitude = model.Longitude; coordToCreate.Truck_Id = model.Truck_Id; var newCoordinate = _coordService.CreateCoordinate(coordToCreate); //creates the favorite var modelWithoutCategories = _mapper.Map <CreateFavoriteModel>(model); var favoriteToCreate = _mapper.Map <Favorite>(modelWithoutCategories); favoriteToCreate.Coordinate_Id = newCoordinate.Id; favoriteToCreate.Coordinates = newCoordinate; var createdFav = _favService.CreateFavorite(favoriteToCreate); //creates initial categories of that favorite pulled from yelp API foreach (string category in model.Categories) { var newCategory = new CreateCategoryModel(); newCategory.Name = category; newCategory.Favorite_Id = createdFav.Id; var categoryToCreate = _mapper.Map <Category>(newCategory); _categoryService.CreateCategory(categoryToCreate); } return(Ok(createdFav)); } catch (AppException ex) { return(BadRequest(new { message = ex.Message })); } }
public IActionResult CreateCategory(Category category) { if (IsAdmin()) { if (ModelState.IsValid) { var search = _categoryServices.GetCategory(category.CategoryId); if (search == null) { if (_categoryServices.CreateCategory(category)) { Alert("Create category successfully!", NotificationType.success); return(RedirectToAction("ManageUser")); } } else { Alert("Category already exist!!", NotificationType.error); return(View()); } } return(View()); } Alert("You not permit to access that page", NotificationType.warning); return(RedirectToAction("Index", "Home")); }
public ActionResult Create(CategoryEntity categoryEntity) { if (ModelState.IsValid) { _categoryServices.CreateCategory(categoryEntity); return(RedirectToAction("Index", "Home")); } return(View(categoryEntity)); }
public IActionResult CreateCategory([FromBody] CreateCategoryModel newCategory) { try { var categoryToCreate = _mapper.Map <Category>(newCategory); _categoryService.CreateCategory(categoryToCreate); return(Ok("Category has been successfully created")); } catch (AppException ex) { return(BadRequest(new { message = ex.Message })); } }
public async Task <IActionResult> Create(CategoryViewModel addCategory) { HttpContext.Session.GetString("fullname"); if (ModelState.IsValid) { if (await _categoryServices.CreateCategory(addCategory)) { TempData["succcessMessage"] = _resourcesServices.GetLocalizedHtmlString("msg_NewCategorySuccess").ToString(); return(RedirectToAction("Index")); } } ViewData["errorMessage"] = _resourcesServices.GetLocalizedHtmlString("msg_NewCategoryError"); return(View(addCategory)); }
public async Task <IActionResult> CreateCategory(CategoryForCreation cateDto) { try { var category = await _categoryServices.CreateCategory(cateDto); if (category == null) { return(new BadRequestObjectResult(new { Message = "Tạo danh mục sản phẩm không thành công" })); } return(Ok(category)); } catch (Exception ex) { return(new BadRequestObjectResult(new { Message = ex.Message.ToString() })); } }
public async Task <BaseResponse <bool> > createCategory([FromBody] Category category) { await _categoryServices.CreateCategory(category); return(new BaseResponse <bool>(true)); }
public IActionResult CreateCategory(Category category) { var newCategory = _categorysServices.CreateCategory(category); return(CreatedAtRoute("GetCategory", new { newCategory.CategoryName }, newCategory)); }