public ResponseInfoModel AddInfo([FromBody] CreateCategoryInput input) { ResponseInfoModel json = new ResponseInfoModel() { Success = 1, Result = new object() }; try { var category = _articleCategoryService.Addinfo(input); if (category == null) { json.Success = 0; json.Result = LocalizationConst.InsertFail; } else { _logService.Insert(new Log() { ActionContent = LocalizationConst.Delete, SourceType = _moduleName, SourceID = category.ID, LogUserID = category.CreateUser, LogTime = DateTime.Now, LogIPAddress = IPHelper.GetIPAddress, }); } } catch (Exception e) { DisposeUserFriendlyException(e, ref json, "api/category/addInfo", LocalizationConst.InsertFail); } return(json); }
public ActionResult Create(CreateCategoryInput viewModel) { try { if (ModelState.IsValid) { viewModel.CompanyName = _currentUser.CompanyName; viewModel.CreatorGuidId = _currentUser.CurrentUserId; _categoryService.Create(viewModel); ModelState.Clear(); var newVm = new CreateCategoryInput(); newVm.ErrorCode = ErrorCodeHelper.Ok; newVm.ErrorDescription = "¡Categoría guardada exitosamente!"; return(PartialView("_createPartial", newVm)); } viewModel.ErrorCode = ErrorCodeHelper.Error; viewModel.ErrorDescription = "Error al intentar guardar los datos."; return(PartialView("_createPartial", viewModel)); } catch (Exception e) { viewModel.ErrorCode = ErrorCodeHelper.Error; viewModel.ErrorDescription = e.Message; return(PartialView("_createPartial", viewModel)); } }
public async Task <IActionResult> Create([FromForm] CreateCategoryInput input) { var absolutePath = Path.Combine(_webHostEnvironment.WebRootPath, Category.IMAGE_PATH); await _categoryService.Create(input, absolutePath); await _dbContext.SaveChangesAsync(); return(Ok()); }
public async Task <ActionResult <ApplicationResult <CategoryDto> > > Post([FromBody] CreateCategoryInput input) { var result = await _categoryService.Create(input); if (result.Succeeded) { return(result); } return(NotFound(result)); }
/// <summary> /// 新增或更改分类 /// </summary> public async Task CreateOrUpdateCategoryAsync(CreateCategoryInput input) { if (input.CategoryEditDto.Id.HasValue) { await UpdateCategoryAsync(input.CategoryEditDto); } else { await CreateCategoryAsync(input.CategoryEditDto); } }
public async Task Create(CreateCategoryInput input, string imageFolderPath) { var imageName = await Upload.UploadImageAsync(input.Image, imageFolderPath); var category = new Category(image: imageName, name: input.Name, priceUnit: input.PriceUnit, status: input.Status, description: input.Description, url: input.Url); await _categoryRepo.Create(category); }
public async Task <ApplicationResult <CategoryDto> > CreateCategory(ApplicationUserDbContext inMemoryContext, IMapper mapper) { var service = new CategoryService(inMemoryContext, mapper); CreateCategoryInput fakeCategory = new CreateCategoryInput { CreatedById = Guid.NewGuid().ToString(), // sahte kullanici CreatedBy = "Tester1", Name = "Lorem Ipsum", UrlName = "lorem-ipsum" }; return(await service.Create(fakeCategory)); }
public async Task <IActionResult> Create(CreateCategoryInput model) { if (ModelState.IsValid) { model.CreatedById = User.FindFirst(ClaimTypes.NameIdentifier).Value; var result = await _categoryService.Create(model); if (result.Succeeded) { return(RedirectToAction("Index")); } } return(View(model)); }
public void Create(CreateCategoryInput input) { var @entity = Category.Create(input.Name, input.Description, input.CreatorGuidId, _dateTime.Now, input.CompanyName); if (@entity == null) { throw new UserFriendlyException("No se pudo crear la Categoría."); } if (_categoryManager.CategoryExist(@entity.Name, input.Id, input.CompanyName)) { throw new UserFriendlyException("Existe una Categoría con el mismo Nombre."); } _categoryRepository.Insert(@entity); }
public ActionResult Create() { CreateCategoryInput viewModel = new CreateCategoryInput(); try { viewModel.CompanyName = _currentUser.CompanyName; viewModel.ErrorCode = ErrorCodeHelper.None; viewModel.ErrorDescription = ""; } catch (Exception e) { viewModel.ErrorCode = ErrorCodeHelper.Error; viewModel.ErrorDescription = "Error al obtener datos."; } return(PartialView("_createPartial", viewModel)); }
public async Task CreateCategory(CreateCategoryInput input) { var domain = _mapper.Map <Category>(input); if (!string.IsNullOrWhiteSpace(input.ParentCategoryId)) { var parentCategory = await _categoryRepository.GetById(input.ParentCategoryId); if (parentCategory == null) { throw new BusinessException("父分类不存在!"); } domain.ParentCategory = parentCategory; } await _categoryRepository.Insert(domain); }
public async Task <BlogResponse> CreateCategoryAsync(CreateCategoryInput input) { var response = new BlogResponse(); var category = await _categories.FindAsync(x => x.Name == input.Name); if (category is not null) { response.IsFailed($"The category:{input.Name} already exists."); return(response); } await _categories.InsertAsync(new Category { Name = input.Name, Alias = input.Alias }); return(response); }
public async Task <ApplicationResult <CategoryDto> > Create(CreateCategoryInput input) { try { var user = await _userManager.FindByIdAsync(input.CreatedById); Category category = new Category { Name = input.Name, UrlName = input.UrlName, CreatedDate = DateTime.Now, CreatedById = input.CreatedById, CreatedBy = user.UserName, }; _context.Categories.Add(category); await _context.SaveChangesAsync(); ApplicationResult <CategoryDto> result = new ApplicationResult <CategoryDto>(); // haftaya bu kod yokalacak yerine automapper metodu gelecek! result.Result = new CategoryDto { CreatedById = category.CreatedById, CreatedDate = category.CreatedDate, CreatedBy = category.CreatedBy, Id = category.Id, Name = category.Name, UrlName = category.UrlName }; result.Succeeded = true; return(result); } catch (Exception e) { ApplicationResult <CategoryDto> result = new ApplicationResult <CategoryDto>(); result.Succeeded = false; // TODO: hata mesajini da gonder return(result); } }
public async Task <ApplicationResult <CategoryDto> > Create(CreateCategoryInput input) { try { var user = await _userManager.FindByIdAsync(input.CreatedById); Category mapCat = _mapper.Map <Category>(input); mapCat.CreatedById = input.CreatedById; mapCat.CreatedBy = user.UserName; _context.Categories.Add(mapCat); await _context.SaveChangesAsync(); ApplicationResult <CategoryDto> result = new ApplicationResult <CategoryDto> { // haftaya bu kod yokalacak yerine automapper metodu gelecek! // AutoMapper ile Category sinifini CategoryDto sinifina donusturebiliriz. //Result = new CategoryDto //{ // CreatedById = category.CreatedById, // CreatedDate = category.CreatedDate, // CreatedBy = category.CreatedBy, // Id = category.Id, // Name = category.Name, // UrlName = category.UrlName //}, Result = _mapper.Map <CategoryDto>(mapCat), Succeeded = true }; return(result); } catch (Exception ex) { ApplicationResult <CategoryDto> result = new ApplicationResult <CategoryDto>(); result.Succeeded = false; result.ErrorMessage = ex.Message; return(result); } }
public ArticleCategory Addinfo(CreateCategoryInput input) { var checkCategory = db.ArticleCategories.FirstOrDefault(a => a.Name == input.Name); if (checkCategory != null) { throw new UserFriendlyException("栏目名重复"); } string guid = Guid.NewGuid().ToString(); int[] orderIDs = db.ArticleCategories.Where(a => a.ParentID == input.ParentID).Select(a => a.OrderID).ToArray(); int orderID = orderIDs.Any() ? orderIDs.Max() + 1 : 1; var category = input.MapTo <ArticleCategory>(); category.CreateTime = DateTime.Now; category.CreateIP = IPHelper.GetIPAddress; category.Guid = guid; category.OrderID = orderID; db.ArticleCategories.Add(category); var attach = input.Attach.MapTo <ArticleAttach>(); if (attach != null) { attach.ModuleType = (int)AttachTypesEnum.文章分类图片; attach.ArticleGuid = guid; attach.CreateTime = DateTime.Now; attach.CreateIP = IPHelper.GetIPAddress; attach.CreateUser = input.CreateUser; attach.AttachIndex = 1; db.ArticleAttaches.Add(attach); } return(db.SaveChanges() > 0 ? category : null); }
public async Task CreateAsync(CreateCategoryInput input) { var @category = Category.Create(input.Title); await _categoryManager.CreateAsync(@category); }
public async Task CreateCategory(CreateCategoryInput input) { var cList = ObjectMapper.Map <Category>(input); await _categoryRepository.InsertAsync(cList); }
/// <exception cref="SwaggerException">A server side error occurred.</exception> public System.Threading.Tasks.Task <FileResponse> CreateCategoryAsync(CreateCategoryInput input) { return(CreateCategoryAsync(input, System.Threading.CancellationToken.None)); }
public async Task Create(CreateCategoryInput input) { var output = ObjectMapper.Map <Category>(input); await _categoryManager.Create(output); }
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param> /// <exception cref="SwaggerException">A server side error occurred.</exception> public async System.Threading.Tasks.Task <FileResponse> CreateCategoryAsync(CreateCategoryInput input, System.Threading.CancellationToken cancellationToken) { if (input == null) { throw new System.ArgumentNullException("input"); } var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/Category"); var client_ = _httpClient; var disposeClient_ = false; try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(input, _settings.Value)); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); request_.Content = content_; request_.Method = new System.Net.Http.HttpMethod("POST"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/octet-stream")); PrepareRequest(client_, request_, urlBuilder_); var url_ = urlBuilder_.ToString(); request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); PrepareRequest(client_, request_, url_); var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); var disposeResponse_ = true; try { var headers_ = System.Linq.Enumerable.ToDictionary(response_.Headers, h_ => h_.Key, h_ => h_.Value); if (response_.Content != null && response_.Content.Headers != null) { foreach (var item_ in response_.Content.Headers) { headers_[item_.Key] = item_.Value; } } ProcessResponse(client_, response_); var status_ = (int)response_.StatusCode; if (status_ == 200 || status_ == 206) { var responseStream_ = response_.Content == null ? System.IO.Stream.Null : await response_.Content.ReadAsStreamAsync().ConfigureAwait(false); var fileResponse_ = new FileResponse(status_, headers_, responseStream_, null, response_); disposeClient_ = false; disposeResponse_ = false; // response and client are disposed by FileResponse return(fileResponse_); } else { var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); throw new SwaggerException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); } } finally { if (disposeResponse_) { response_.Dispose(); } } } } finally { if (disposeClient_) { client_.Dispose(); } } }
public async Task CreateCategory(CreateCategoryInput input) { var category = input.MapTo <Category>(); await _categoryRepository.InsertAsync(category); }
public async Task InsertCategory([FromBody] CreateCategoryInput input) { await _categoryService.CreateCategory(input); }
public async Task Create(CreateCategoryInput input) { var category = _mapper.Map <Category>(input); await _categoryManager.Create(category); }
public async Task Create(CreateCategoryInput input) { Category output = Mapper.Map <CreateCategoryInput, Category>(input); await _categoryManager.Create(output); }
public async Task GetAllCategory() { var options = new DbContextOptionsBuilder <ApplicationUserDbContext>().UseInMemoryDatabase(databaseName: "Test_GetAllCategory").Options; MapperConfiguration mappingConfig = new MapperConfiguration(mc => { mc.AddProfile(new AutoMapperProfile()); }); IMapper mapper = mappingConfig.CreateMapper(); List <ApplicationResult <CategoryDto> > resultCreates = new List <ApplicationResult <CategoryDto> >(); // Iki kategori olustur using (var inMemoryContext = new ApplicationUserDbContext(options)) { var fakeCategory1 = new CreateCategoryInput { CreatedById = Guid.NewGuid().ToString(), // sahte kullanici CreatedBy = "Tester1", Name = "Lorem Ipsum 1", UrlName = "lorem-ipsum-1" }; var fakeCategory2 = new CreateCategoryInput { CreatedById = Guid.NewGuid().ToString(), // sahte kullanici CreatedBy = "Tester2", Name = "Lorem Ipsum 2", UrlName = "lorem-ipsum-2" }; resultCreates.Add(await CreateCategory(inMemoryContext, mapper, fakeCategory1)); resultCreates.Add(await CreateCategory(inMemoryContext, mapper, fakeCategory2)); } ApplicationResult <List <CategoryDto> > resultGetAll = new ApplicationResult <List <CategoryDto> >(); // create servis dogru calistimi kontrol et ve get servisi calistir using (var inMemoryContext = new ApplicationUserDbContext(options)) { // create servis duzgun calisti mi? foreach (var resultCreate in resultCreates) { Assert.True(resultCreate.Succeeded); Assert.NotNull(resultCreate.Result); } // get islemini calistir var service = new CategoryService(inMemoryContext, mapper); resultGetAll = await service.GetAll(); } // get servis dogru calistimi kontrol et using (var inMemoryContext = new ApplicationUserDbContext(options)) { // get servis dogru calisti mi kontrolu Assert.True(resultGetAll.Succeeded); Assert.NotNull(resultGetAll.Result); Assert.Equal(2, await inMemoryContext.Categories.CountAsync()); var items = await inMemoryContext.Categories.ToListAsync(); Assert.Equal("Lorem Ipsum 1", items[0].Name); Assert.Equal("lorem-ipsum-1", items[0].UrlName); Assert.Equal("Lorem Ipsum 2", items[1].Name); Assert.Equal("lorem-ipsum-2", items[1].UrlName); } }
public async Task AssertCreatedCategory(ApplicationUserDbContext inMemoryContext, ApplicationResult <CategoryDto> resultCreate, CreateCategoryInput fakeCategory) { Assert.True(resultCreate.Succeeded); Assert.NotNull(resultCreate.Result); Assert.Equal(1, await inMemoryContext.Categories.CountAsync()); var item = await inMemoryContext.Categories.FirstOrDefaultAsync(); Assert.Equal(fakeCategory.CreatedBy, item.CreatedBy); Assert.Equal(fakeCategory.Name, item.Name); Assert.Equal(fakeCategory.UrlName, item.UrlName); Assert.Equal(resultCreate.Result.CreatedById, item.CreatedById); }
public async Task <ApplicationResult <CategoryDto> > CreateCategory(ApplicationUserDbContext inMemoryContext, IMapper mapper, CreateCategoryInput fakeCategory) { var service = new CategoryService(inMemoryContext, mapper); return(await service.Create(fakeCategory)); }