public async Task <ActionResult <Category> > PostCategory(Category category) { _ICategory.Add(category); await _ICategory.SaveAsync(); return(CreatedAtAction("GetCategory", new { id = category.CategoryId }, category)); }
public async Task <CategoryResponse> Add(CategoryRequest request) { CategoryResponse response = new CategoryResponse(); try { Category category = new Category(); if (!(await iCategory.IsDuplicate(request.CategoryName))) { category.CategoryName = request.CategoryName; category.Description = request.Description; category.Created = DateTime.Now; category.CreatedBy = request.CurrentLogin; category.RowStatus = true; if (await iCategory.Add <Category>(category)) { return(response); } response.Message = "Failed to Add Category"; response.IsSuccess = false; } else { response.Message = "Category is Duplicated with existing"; response.IsSuccess = false; } } catch (Exception ex) { response.IsSuccess = false; response.Message = "Something Error in Our System : " + ex.Message; } return(response); }
public async Task <IActionResult> PostCategory(CategoryDto categoryDto) { var category = _mapper.Map <Category>(categoryDto); await _repo.Add(category); var categoryToReturn = _mapper.Map <CategoryDto>(category); return(CreatedAtAction("GetCategory", new { id = categoryToReturn.Id }, categoryToReturn)); }
public IActionResult Create([Bind("Name,Id")] TransactionCategory transactionCategory) { if (ModelState.IsValid) { _categoryService.Add(transactionCategory); return(RedirectToAction(nameof(Index))); } return(View(transactionCategory)); }
public async Task <BookModel> Add(BookModel book) { if (book == null) { return(null); } if (book.Id > 0) { return(book); } try { if (book.Categories != null) { foreach (BookCategoryModel category in book.Categories) { await _category.Add(category); } } if (book.Authors != null) { foreach (AuthorModel author in book.Authors) { await _author.Add(author); } } if (book.Publisher != null) { await _publisher.Add(book.Publisher); } _context.Add(book); await _context.SaveChangesAsync(); return(book); } catch (Exception ex) { string message = ex.Message; return(null); } }
public IHttpActionResult Add(TOURIS_TV_CATEGORY categoryView) { ApiResData res = new ApiResData(); try { if (!ModelState.IsValid) { rs.SetErrorStatus(eFunc.fg.SFailed); resObj = JObject.FromObject(res.ResCUD(new object[] { rs }, eFunc.fg.Save, new Exception(eFunc.fg.DataIsntValid))); return(Content(HttpStatusCode.NotFound, resObj)); } TOURIS_TM_CATEGORY category = new TOURIS_TM_CATEGORY(); category.CATEGORY_CODE = categoryView.CATEGORY_CODE; category.CATEGORY_NAME = categoryView.CATEGORY_NAME; category.CATEGORY_DESCRIPTION = categoryView.CATEGORY_DESCRIPTION; category.URL = categoryView.URL; category.CLASS = categoryView.CLASS; category.PHOTO_PATH = categoryView.PHOTO_PATH; category.CREATED_BY = categoryView.CREATED_BY; category.CREATED_TIME = categoryView.CREATED_TIME; category.ROW_STATUS = eStat.fg.IsActive; rs = repo.Add(category); if (rs.IsSuccess) { rs.SetSuccessStatus(); } else { rs.SetErrorStatus(eFunc.fg.SFailed); } resObj = JObject.FromObject(res.ResCUD(new object[] { rs }, eFunc.fg.Save, null)); return(Content(HttpStatusCode.OK, resObj)); } catch (Exception ex) { rs.SetErrorStatus(ex.Message); resObj = JObject.FromObject(res.ResCUD(new object[] { rs }, eFunc.fg.Save, new Exception(eFunc.fg.SFailed))); return(Content(HttpStatusCode.BadRequest, resObj)); } }
public ActionResult ActionCreate(SBH_TM_CATEGORY categoryView, HttpPostedFileBase postedFile) { try { string encodedString = Server.HtmlEncode(categoryView.DESCRIPTION); categoryView.DESCRIPTION = encodedString; string physicalPath = ""; if (postedFile != null) { string ImageName = System.IO.Path.GetFileName(postedFile.FileName); //file2 to store path and url physicalPath = Server.MapPath("~" + Common.GetPathFolderImg() + ImageName); //categoryView.IMAGE_PATH = Common.GetPathFolderImg() + ImageName; } categoryView.CREATED_BY = Session["UserId"].ToString(); categoryView.CREATED_TIME = DateTime.Now; rs = repo.Add(categoryView); if (rs.IsSuccess) { if (physicalPath != "") { postedFile.SaveAs(physicalPath); } rs.SetSuccessStatus("Data has been created successfully"); TempData["msgSuccess"] = rs.MessageText; } else { rs.SetErrorStatus("Data failed to created"); TempData["msgError"] = rs.MessageText; } } catch (Exception ex) { ModelState.AddModelError("", ex.Message); rs.SetErrorStatus("Data failed to created"); TempData["msgError"] = rs.MessageText; } return(RedirectToAction("Index")); }
public async Task <ActionResult> Create(CategoryViewModel categoryViewModel) { if (ModelState.IsValid) { string UrlImage = ""; var files = HttpContext.Request.Form.Files; foreach (var Image in files) { if (Image != null && Image.Length > 0) { var file = Image; var uploads = Path.Combine(hostingEnvironment.WebRootPath, "uploads/category"); if (file.Length > 0) { // var fileName = Guid.NewGuid().ToString().Replace("-", "") + Path.GetExtension(file.FileName); var fileName = Guid.NewGuid().ToString().Replace("-", "") + file.FileName; using (var fileStream = new FileStream(Path.Combine(uploads, fileName), FileMode.Create)) { await file.CopyToAsync(fileStream); UrlImage = fileName; } } } } Category category = new Category { Id = categoryViewModel.Id, Image = UrlImage, Name = categoryViewModel.Name, Description = categoryViewModel.Description, }; categoryRepository.Add(category); return(RedirectToAction(nameof(Index))); } return(View()); }
public async Task <IActionResult> Post([FromBody] Category category) { try { if (ModelState.IsValid) { if (_context.Categories.Any(c => c.Title == category.Title)) { ModelState.AddModelError("Title", "Category with this title already exists"); } await _categoryService.Add(category); await _context.SaveChangesAsync(); } } catch (DataException /* dex */) { //Log the error (uncomment dex variable name and add a line here to write a log. return(BadRequest("Unable to save changes. Try again...")); } return(CreatedAtAction(nameof(Get), new { id = category.Id }, category)); }
public async Task <IActionResult> Create([Bind("Title, Description, Created")] Category category) { try { if (ModelState.IsValid) { if (_context.Categories.Any(c => c.Title == category.Title)) { ModelState.AddModelError("Title", "Category with this title already exists"); return(View(category)); } await _categoryService.Add(category); return(RedirectToAction("Index", "Home")); } } catch (DataException /* dex */) { //Log the error (uncomment dex variable name and add a line here to write a log. ModelState.AddModelError("", "Unable to save changes. Try again..."); } return(View(category)); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Leadin.Model.Category model) { return(dal.Add(model)); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(TravelAgent.Model.Category model) { CategoryDAL.Add(model); return(CategoryDAL.GetMaxID("Id")); }
public void Post([FromBody] Category category) { _category.Add(category); }
public static int AddCategory(CategoryInfo category) { ICategory dal = Factory <ICategory> .Create("Category"); return(dal.Add(category)); }
public IActionResult Add(CategoryViewModel vm) { catRepo.Add(vm); return(RedirectToAction(nameof(Index))); }
public void AddCategory(Category category) { _categoryService.Add(category); }
public object CategoryAdd([FromBody] string name) { _Category.Add(name); return(name); }
/// <summary> /// 保存添加数据 Add(CategoryInfo entity) /// </summary> /// <param name="entity">实体类(CategoryInfo)</param> ///<returns>返回新增的ID</returns> public void Add(CategoryInfo entity) { _category.Add(entity); }