public async Task <BaseResponse> AddCategroyAsync(string Account, CategoryAddDto req) { var cate = await _cr.Find(a => a.Name == req.Name).FirstOrDefaultAsync(); if (cate != null) { return(new BaseResponse { Success = false, Message = "已存在相同名称的分类" }); } try { var entity = _map.Map <CategoryModel>(req); entity.Create = Account; await _cr.AddAsync(entity); _log.LogInformation($"{Account}添加标示为{entity.Id}的分类成功"); return(new HandleResponse <int> { Success = true, Message = "添加数据成功", Key = entity.Id }); } catch (Exception ex) { _log.LogError($"{Account}添加分类失败,失败原因:{ex.Message}->{ex.StackTrace}->{ex.InnerException}"); return(new BaseResponse { Success = false, Message = "添加数据失败,请联系管理员" }); } }
public async Task <IActionResult> Add(CategoryAddDto categoryAddDto) { if (ModelState.IsValid) { //eğer eklenecek olan veride bir hata yoksa dn ye ekliyoruz daha sonra Success olan veriyi kull. tekrardan göst. icin //Json'a donust. ve eklenen result verisinin datasını alıyoruz ve göst. olan sayfaya render ediyoruz. var result = await _categoryService.Add(categoryAddDto, "Ahmet"); if (result.ResultStatus == ResultStatus.Success) { var categoryAddAjaxModel = JsonSerializer.Serialize(new CategoryAddAjaxViewModel() { CategoryDto = result.Data, CategoryAddPartial = await this.RenderViewToStringAsync("_CategoryAddPartial", categoryAddDto) }); return(Json(categoryAddAjaxModel)); } } var categoryAddAjaxErrorModel = JsonSerializer.Serialize(new CategoryAddAjaxViewModel() { CategoryAddPartial = await this.RenderViewToStringAsync("_CategoryAddPartial", categoryAddDto), }); return(Json(categoryAddAjaxErrorModel)); }
public async Task <IDataResult <CategoryDto> > AddAsync(CategoryAddDto categoryAddDto, string createdByName) // Task<IResult> -> Task<IDataResult<CategoryDto>> { var category = Mapper.Map <Category>(categoryAddDto); category.CreatedByName = createdByName; category.ModifiedByName = createdByName; var addedCategory = await UnitOfWork.Categories.AddAsync(category); //var addedCategory, bu Add işlemi bize category dönüyor await UnitOfWork.SaveAsync(); //.ContinueWith(t => UnitOfWork.SaveAsync()); Bunu kaldırdık çünkü dbcontext Thread-Safe değil. Continue with 2. thread isteği yapan bir fonksiyon. Add-Update-Delete-HardDelete gibi kısımlarda gerekli bu işlem return(new DataResult <CategoryDto>(ResultStatus.Success, Messages.Category.Add(addedCategory.Name), new CategoryDto { Category = addedCategory, ResultStatus = ResultStatus.Success, Message = Messages.Category.Add(addedCategory.Name) })); //await UnitOfWork.Categories.AddAsync(new Category //kategoriyi gönderirken oluşturuyoruz //{ // Name = categoryAddDto.Name, // Description = categoryAddDto.Description, // Note = categoryAddDto.Note, // IsActive = categoryAddDto.IsActive, // CreatedByName = createdByName, //parametre olarak geliyor // CreatedDate = DateTime.Now, //Buradan aşağısı zaten zaten otomatik geliyor ama yine de yazdık // ModifiedByName = createdByName, // ModifiedDate = DateTime.Now, // IsDeleted = false //}).ContinueWith(t => UnitOfWork.SaveAsync()); //işlemi bitirip diğer taske geçmeden hızlı şekilde saveliyor ////await UnitOfWork.SaveAsync(); //return new Result(ResultStatus.Success, $"{categoryAddDto.Name} adlı kategori başarıyla eklenmiştir."); // Gönderilen veri henüz kaydedilmeden (continuewith sayesinde) önyüze geçmemizi sağlıyor, bu hız kazandırıyor bize ama yönetimi zorlaştırıyor }
public async Task <IActionResult> Add(CategoryAddDto categoryAddDto) { #region Startup JsonSerializer ayarından önce //var categoryAjaxModel = new CategoryAddAjaxViewModel //{ // CategoryAddPartial = await this.RenderViewToStringAsync("_CategoryAddPartial", categoryAddDto), //}; #endregion if (ModelState.IsValid) { var result = await _categoryService.AddAsync(categoryAddDto, LoggedInUser.UserName); if (result.ResultStatus == ResultStatus.Success) { var categoryAddAjaxModel = JsonSerializer.Serialize(new CategoryAddAjaxViewModel { CategoryDto = result.Data, CategoryAddPartial = await this.RenderViewToStringAsync("_CategoryAddPartial", categoryAddDto) }); return(Json(categoryAddAjaxModel)); } } var categoryAddAjaxErrorModel = JsonSerializer.Serialize(new CategoryAddAjaxViewModel { CategoryAddPartial = await this.RenderViewToStringAsync("_CategoryAddPartial", categoryAddDto) }); return(Json(categoryAddAjaxErrorModel)); }
public async Task AddPost(CategoryAddDto category) { if (category != null) { await _categoryRepository.Add(_mapper.Map <Category>(category)); } }
public async Task <bool> UpdateCategory(int id, CategoryAddDto categoryAdd) { Category newCategory = mapper.Map <Category>(categoryAdd); newCategory.CategoryId = id; bool result; try { int resultUpdate = await _categoryRepository.UpdateCategory(newCategory); if (resultUpdate > 0) { result = true; } else { result = false; } } catch (Exception exc) { _logger.LogError(exc.Message); result = false; } return(result); }
public async Task <DataResult <CategoryModel> > AddCategoryAsync(CategoryAddDto category) { using (var context = new LangiumDbContext()) { try { var newCategory = new CategoryModel() { Name = category.Name, Description = category.Description, Words = new List <WordModel>(), ProfileId = category.ProfileId }; var categoryWithSameName = await context.Categories.FirstOrDefaultAsync(c => c.Name == category.Name && c.ProfileId == category.ProfileId); if (categoryWithSameName == null) { var added = await context.Categories.AddAsync(newCategory); await context.SaveChangesAsync(); return(new DataResult <CategoryModel>(added.Entity)); } else { return(new DataResult <CategoryModel>(null, "CATEGORY_WITH_SAME_NAME_AlREADY_EXISTS")); } } catch (Exception ex) { return(new DataResult <CategoryModel>(ex, ex.InnerException.Message)); } } }
public async Task <IDataResult <CategoryDto> > Add(CategoryAddDto categoryAddDto, string createdByName) { //***********************Auto Mapper Kullandıktan Sonraki Hali********************** var category = _mapper.Map <Category>(categoryAddDto); category.CreatedByName = createdByName; category.ModifiedByName = createdByName; var addedCategory = await _unitOfWork.Categories.AddAsync(category); await _unitOfWork.SaveAsync(); return(new DataResult <CategoryDto>(ResultStatus.Success, $"{categoryAddDto.Name} adlı kategori başarıyla eklenmiştir.", new CategoryDto { Category = addedCategory, ResultStatus = ResultStatus.Success, Message = $"{categoryAddDto.Name} adlı kategori başarıyla eklenmiştir." })); //***********************Auto Mapper Kullanmadan Önceki Hali*********************** //await _unitOfWork.Categories.AddAsync(new Category //{ // Name = categoryAddDto.Name, // Description = categoryAddDto.Description, // Note = categoryAddDto.Note, // IsActive = categoryAddDto.IsActive, // CreatedByName = createdByName, // CreatedDate = DateTime.Now, // ModifiedByName = createdByName, // ModifiedDate = DateTime.Now, // IsDeleted = false //}).ContinueWith(t => _unitOfWork.SaveAsync());//daha hızlı olması artı ama asenkron olduğu için işlemi yaparken başarılı mesajı veriliyor ////await _unitOfWork.SaveAsync(); //return new Result(ResultStatus.Success, $"{categoryAddDto.Name} adlı kategori başarıyla eklenmiştir."); }
private void button2_Click(object sender, EventArgs e) { string categoryName = categoryBox.Text; double limit = double.Parse(categoryLimit.Text); KeyValuePair <string, int> keyValue = (KeyValuePair <string, int>)comboBox1.SelectedItem; string key = keyValue.Key; int value = keyValue.Value; if (categoryName.Equals("")) { MessageBox.Show("Please Enter Category Name"); } CategoryAddDto categoryAdd = new CategoryAddDto(); categoryAdd.categoryName = categoryName; categoryAdd.categoryType = key; categoryAdd.categoryLimit = limit; XmlSerializer serializer = new XmlSerializer(typeof(CategoryAddDto)); using (FileStream fs = new FileStream(Environment.CurrentDirectory + "\\category.xml", FileMode.Create, FileAccess.Write)) { serializer.Serialize(fs, categoryAdd); MessageBox.Show("Xml File Created", "Success"); } }
public async Task <ActionResult <BaseResponse> > AddCategory([FromBody] CategoryAddDto req) { string Account = User.Claims.FirstOrDefault(a => a.Type == "Account").Value; var rm = await _cs.AddCategroyAsync(Account, req); return(rm); }
public async Task <IResult> Add(CategoryAddDto categoryAddDto, string createdByName) { var category = _mapper.Map <Category>(categoryAddDto); category.CreatedByName = createdByName; category.ModifiedByName = createdByName; await _unitOfWork.Categories.AddAsync(category).ContinueWith(t => _unitOfWork.SaveAsync()); //AutoMapper olmadan yapılışı //await _unitOfWork.Categories.AddAsync(new Category //{ // Name = categoryAddDto.Name, // Description = categoryAddDto.Description, // Note = categoryAddDto.Note, // IsActive = categoryAddDto.IsActive, // CreatedByName = createdByName, // CreatedDate = DateTime.Now, // ModifiedByName = createdByName, // ModifiedDate = DateTime.Now, // IsDeleted = false //}).ContinueWith(t => _unitOfWork.SaveAsync()); // ekleme bittikten sonra task ile devam ediyor ////performansı çok etkiliyor //// js de then gibi bir ifadedir. fakat çok hızlı oluyor bu işlemler ////await _unitOfWork.SaveAsync(); // veriler eklendi fakat save edilmediği için SaveAsync çalıştırıyoruz return(new Resulst(ResultStatus.Success, $"{categoryAddDto.Name} adlı kategori başarıyla eklendi.")); }
public async Task <IActionResult> Add(CategoryAddDto categoryAddDto) { if (ModelState.IsValid) { var result = await _categoryService.Add(categoryAddDto, "Eray Bakır"); if (result.ResultStatus == ResultStatus.Success) { var categoryAjaxModel = JsonSerializer.Serialize(new CategoryAddAjaxViewModel { CategoryDto = result.Data, CategoryAddPartial = await this.RenderViewToStringAsync("_CategoryAddPartial", categoryAddDto) }); return(Json(categoryAjaxModel)); } } var categoryAjaxInvalidrModel = JsonSerializer.Serialize(new CategoryAddAjaxViewModel { CategoryAddPartial = await this.RenderViewToStringAsync("_CategoryAddPartial", categoryAddDto) }); return(Json(categoryAjaxInvalidrModel)); }
public async Task <Category> Create(CategoryAddDto category) { await _genericDal.AddAsync(new Category() { Name = category.Name }); return(null); }
public async Task <IActionResult> Create(CategoryAddDto category) { if (ModelState.IsValid) { await _categoryManager.Create(category); return(RedirectToAction("Index")); } return(View()); }
public async Task <IActionResult> Add(CategoryAddDto category) { if (ModelState.IsValid) { await _categoryService.AddAsync(category.Adapt <Category>()); return(RedirectToAction("Index", "Category", new { area = "Admin" })); } return(View(category)); }
public async void Add_ShouldReturnBadRequest_WhenModelStateIsInvalid() { var categoryAddDto = new CategoryAddDto(); _categoriesController.ModelState.AddModelError("Name", "The field name is required"); var result = await _categoriesController.Add(categoryAddDto); Assert.IsType <BadRequestResult>(result); }
public async Task <IResult> Add(CategoryAddDto categoryAddDto, string createdByName) { var category = _mapper.Map <Category>(categoryAddDto); category.CreatedByName = createdByName; category.ModifiedByName = createdByName; await _unitOfWork.Categories.AddAsync(category).ContinueWith(t => _unitOfWork.SaveAsync());//await _unitOfWork.SaveAsync(); return(new Result(ResultStatus.Success, $"{categoryAddDto.Name} adlı kategori başarıyla eklenmiştir.")); }
public async Task <IActionResult> Create(CategoryAddDto model) { if (ModelState.IsValid) { await _categoryService.AddAsync(_mapper.Map <Category>(model)); return(RedirectToAction("Index")); } return(View(model)); }
public IActionResult AddCategory(CategoryAddDto model) { if (ModelState.IsValid) { _categoryService.Add(_mapper.Map <Category>(model)); return(RedirectToAction("Index")); } return(View(model)); }
public async Task <IActionResult> AddCategory(CategoryAddDto model) { if (ModelState.IsValid) { await _categoryService.AddAsync(_mapper.Map <Category>(model)); return(RedirectToAction("Index", "Category", new { area = "Member" })); } return(View(model)); }
public async Task <IActionResult> Add(CategoryAddDto categoryAddDto) { if (ModelState.IsValid) { await _categoryService.Add(categoryAddDto, "Hasan Erdal"); return(RedirectToAction("Index")); } return(View(categoryAddDto)); }
public async Task <ActionResult <CategoryAddDto> > Get(int id) { CategoryAddDto categoryDto = await _categoryBusiness.GetCategoryById(id); if (categoryDto == null) { return(NotFound()); } return(categoryDto); }
public IResult Add(CategoryAddDto categoryAddDto, string createdByName) { var category = _mapper.Map <Category>(categoryAddDto); category.CreatedDate = DateTime.Now; category.CreatedByName = createdByName; category.ModifiedByName = createdByName; _unitOfWork.Categories.Add(category); _unitOfWork.Save(); return(new Result(ResultStatus.Success, $"{categoryAddDto.Name} adlı kategori başarı ile eklenmiştir")); }
public async Task <IResult> Add(CategoryAddDto categoryAddDto, string createdByName) { var category = _mapper.Map <Category>(categoryAddDto); category.CreatedByName = createdByName; category.ModifiedByName = createdByName; await _unitOfWork.Categories.AddAsync(category) .ContinueWith(t => _unitOfWork.SaveAsync()); // hızlı bir işlem front a hemen dönücek veritabanına yazmadan Javascript kullanacağımız için bu daha mantıklı ekran hızlı olacak //await _unitOfWork.SaveAsync(); return(new Result(ResultStatus.Success, $"{categoryAddDto.Name} adlı kategori başarıyla eklenmiştir.")); }
public async Task <ActionResult <CategoryAddDto> > Get(int id) { CategoryAddDto categoryDto = await new CategoryBusiness(_categoryRepository, _logger) .GetCategoryById(id); if (categoryDto == null) { return(NotFound()); } return(categoryDto); }
private void button3_Click(object sender, EventArgs e) { XmlSerializer serializer = new XmlSerializer(typeof(CategoryAddDto)); CategoryAddDto categoryAddDto = new CategoryAddDto(); using (FileStream fs = new FileStream(Environment.CurrentDirectory + "\\category.xml", FileMode.Open, FileAccess.Read)) { categoryAddDto = serializer.Deserialize(fs) as CategoryAddDto; categoryBox.Text = categoryAddDto.categoryName; categoryLimit.Text = categoryAddDto.categoryLimit.ToString(); comboBox1.Text = categoryAddDto.categoryType; } }
public async Task <ActionResult <CategoryModel> > Post(CategoryAddDto category) { var result = await _dao.AddCategoryAsync(category); if (result.Data != null) { return(Ok(result)); } else { return(BadRequest(result)); } }
public async Task <IActionResult> Add(CategoryAddDto categoryAddDto) { if (!ModelState.IsValid) { return(View(categoryAddDto).ShowMessage(Status.Error, "Hata", "Eksik veya hatalı bilgiler mevcut!")); } var category = _mapper.Map <Category>(categoryAddDto); await _categoryService.AddAsync(category); return(RedirectToAction("Index").ShowMessage(Status.Ok, "Başarılı", "Kategori başarıyla eklendi!")); }
public async Task <IActionResult> AddCategory(CategoryAddDto categoryAddDto) { Category addCategory = _mapper.Map <Category>(categoryAddDto); if (await _categoryRepository.AddAsync(addCategory)) { return(Ok(addCategory)); } else { return(BadRequest("Category Can't Added")); } }
public async Task <IActionResult> Create(CategoryAddDto categoryAddDto) { if (ModelState.IsValid) { await _categoryService.InsertAsync(new Category { Name = categoryAddDto.Name }); return(RedirectToAction("Index", "Category")); } return(View(categoryAddDto)); }