public async Task <ApplicationResult <ProductDto> > MakeOffer(ProductDto model) { try { var getExistProduct = await _context.Products.FindAsync(model.Id); if (getExistProduct == null) { return(new ApplicationResult <ProductDto> { Result = new ProductDto(), Succeeded = false, ErrorMessage = "Böyle bir ürün bulunamadı" }); } if (getExistProduct.ProductHighOfferPrice < model.ProductHighOfferPrice && getExistProduct.StartOfferPrice < model.ProductHighOfferPrice) { getExistProduct.ProductHighOfferPrice = model.ProductHighOfferPrice; getExistProduct.HighestBidderById = model.HighestBidderById; getExistProduct.HighestBidderBy = model.HighestBidderBy; getExistProduct.HighOfferDateTime = DateTime.UtcNow; _context.Update(getExistProduct); await _context.SaveChangesAsync(); return(new ApplicationResult <ProductDto> { Succeeded = true, }); } return(new ApplicationResult <ProductDto> { Succeeded = false, ErrorMessage = "Tekifiniz, açık arttırma başlangıç fiyatından ve en yüksek son tekliften daha yüksek olmalıdır!" }); } catch (Exception e) { return(new ApplicationResult <ProductDto> { Result = new ProductDto(), Succeeded = false, ErrorMessage = e.Message }); } }
public async Task <ApplicationResult <PostDto> > Update(UpdatePostInput input) { try { var getExistPost = await _context.Posts.FindAsync(input.Id); // hata var mi kontrol ediyoruz varsa demekki boyle bir post yok if (getExistPost == null) { return(new ApplicationResult <PostDto> { Result = new PostDto(), Succeeded = false, ErrorMessage = "Böyle bir Post bulunamadı" }); } // useri al // var user = await _userManager.FindByIdAsync(input.CreatedById); // getExistPost.ModifiedBy = user.UserName; _mapper.Map(input, getExistPost); _context.Update(getExistPost); await _context.SaveChangesAsync(); return(await Get(getExistPost.Id)); } catch (Exception ex) { return(new ApplicationResult <PostDto> { Result = new PostDto(), Succeeded = false, ErrorMessage = ex.Message }); } }
public async Task <ApplicationResult <BrandDto> > Update(UpdateBrandViewModel model) { try { var getExistBrand = await _context.Brands.FindAsync(model.Id); if (getExistBrand == null) { return(new ApplicationResult <BrandDto> { Result = new BrandDto(), Succeeded = false, ErrorMessage = "Böyle bir Marka bulunamadı!" }); } var modifierUser = await _userManager.FindByIdAsync(model.CreatedById); getExistBrand.ModifiedBy = modifierUser.UserName; _mapper.Map(model, getExistBrand); _context.Update(getExistBrand); await _context.SaveChangesAsync(); return(await Get(getExistBrand.Id)); } catch (Exception e) { return(new ApplicationResult <BrandDto> { Result = new BrandDto(), Succeeded = false, ErrorMessage = e.Message }); } }
public async Task <ApplicationResult <SubCategoryDto> > Update(UpdateSubCategoryViewModel model) { try { var getExistSubCategory = await _context.SubCategories.FindAsync(model.Id); if (getExistSubCategory == null) { return(new ApplicationResult <SubCategoryDto> { Result = new SubCategoryDto(), Succeeded = false, ErrorMessage = "Böyle bir Kategori bulunamadı" }); } var modifierUser = await _userManager.FindByIdAsync(model.ModifiedById); getExistSubCategory.ModifiedBy = modifierUser.UserName; _mapper.Map(model, getExistSubCategory); _context.Update(getExistSubCategory); await _context.SaveChangesAsync(); return(await Get(getExistSubCategory.Id)); } catch (Exception e) { return(new ApplicationResult <SubCategoryDto> { Result = new SubCategoryDto(), Succeeded = false, ErrorMessage = e.Message }); } }
/// <summary> /// 更新角色 /// </summary> /// <param name="role"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <IdentityResult> UpdateAsync(SysRole role, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); if (role == null) { throw new ArgumentNullException(nameof(role)); } _db.Update(role); await _db.SaveChangesAsync(); return(IdentityResult.Success); }
public async Task <ApplicationResult <CategoryDto> > Update(UpdateCategoryInput input) { try { var modifierUser = await _userManager.FindByIdAsync(input.ModifiedById); var getExistCategory = await _context.Categories.FindAsync(input.Id); getExistCategory.Name = input.Name; getExistCategory.UrlName = input.UrlName; getExistCategory.ModifiedBy = modifierUser.UserName; getExistCategory.ModifiedById = modifierUser.Id; getExistCategory.ModifiedDate = DateTime.UtcNow; _context.Update(getExistCategory); await _context.SaveChangesAsync(); return(new ApplicationResult <CategoryDto> { Succeeded = true, Result = new CategoryDto { CreatedBy = getExistCategory.CreatedBy, CreatedById = getExistCategory.CreatedById, CreatedDate = getExistCategory.CreatedDate, Id = getExistCategory.Id, ModifiedBy = getExistCategory.ModifiedBy, ModifiedById = getExistCategory.ModifiedById, ModifiedDate = getExistCategory.ModifiedDate, Name = getExistCategory.Name, UrlName = getExistCategory.UrlName } }); } catch (Exception ex) { return(new ApplicationResult <CategoryDto> { Succeeded = false, ErrorMessage = ex.Message, Result = new CategoryDto() }); } }
/// <summary> /// 更新用户信息 /// </summary> /// <param name="user"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <IdentityResult> UpdateAsync(SysUser user, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); if (user == null) { throw new ArgumentNullException(nameof(user)); } if (string.IsNullOrEmpty(user.Email)) { user.EmailConfirmed = false; } if (string.IsNullOrEmpty(user.PhoneNumber)) { user.PhoneNumberConfirmed = false; } _db.Update(user); await _db.SaveChangesAsync(); return(IdentityResult.Success); }