/// <summary> /// 批量插入测试 /// 方法1耗时16秒以上 /// 方法2耗时22秒以上 /// </summary> /// <returns></returns> public ActionResult Index() { var sw = new Stopwatch(); var sw2 = new Stopwatch(); #region 构造数据 var random = new Random(); var list = new List <Coupon>(); for (var i = 0; i < 1000; i++) { list.Add(new Coupon { Number = DateTime.Now.ToString("HHmmss") + random.Next(10000000, 100000000), Price = 10, Status = EnumCouponStatus.Actived, CouponCategoryId = 1 }); } #endregion sw.Start(); _couponService.BulkCreate(list); sw.Stop(); sw2.Start(); foreach (var p in list) { _couponService.Create(p); } sw2.Stop(); @ViewBag.t1 = sw.ElapsedMilliseconds.ToString(CultureInfo.InvariantCulture); @ViewBag.t2 = sw2.ElapsedMilliseconds.ToString(CultureInfo.InvariantCulture); return(View()); }
public ActionResult Save(CouponListViewModel couponVM) { if (!ModelState.IsValid) { return(View("CouponForm", couponVM)); } //New if (couponVM.CouponId == null) { var cookie = Request.Cookies["idCookie"]; var R_Id = cookie.Values["r_id"]; Coupons instance = new Coupons { CouponId = Guid.NewGuid().ToString("N"), R_Id = R_Id, StartTime = couponVM.StartTime, EndTime = couponVM.EndTime, Title = couponVM.Title, Desciption = couponVM.Desciption }; couponService.Create(instance); } else { var coupon = couponService.GetByID(couponVM.CouponId); Mapper.Map <CouponListViewModel, Coupons>(couponVM, coupon); couponService.Update(coupon); } return(RedirectToAction("Index")); }
public bool Post(CouponModel model) { var entity = new CouponEntity { Guid = model.Guid, Type = model.Type, DisCount = model.DisCount, // Product = model.Product, ExpireTime = model.ExpireTime, Status = model.Status, Adduser = model.Adduser, Addtime = model.Addtime, Upduser = model.Upduser, Updtime = model.Updtime, Owner = model.Owner, }; if (_CouponService.Create(entity).Id > 0) { return(true); } return(false); }
public async Task <IActionResult> Create([FromBody] CouponCreateRequest request) { var result = await _couponService.Create(request); if (!result.IsSuccess) { return(BadRequest(result)); } return(Ok(result)); }
public IActionResult Create(CouponAddVM coupon) { try { _couponService.Create(coupon); return(Ok("Good")); } catch (Exception ex) { return(BadRequest("Something went wrong")); } }
public async Task <IActionResult> Add([FromBody] CouponDto coupon) { try { coupon.Id = Guid.NewGuid(); _couponService.Create(coupon); return(CreatedAtAction(nameof(GetById), new { version = HttpContext.GetRequestedApiVersion().ToString(), id = coupon.Id }, coupon)); } catch (Exception e) { _loggerManager.LogError($"Ocurrio un error cuando se intentaba guardar el cupon: {e}"); throw new ApiException(AppResources.BadRequest, HttpStatusCode.BadRequest); } }
public HttpResponseMessage Create(CouponModel model) { Random random = new Random(); int num = random.Next(10000000, 100000000); var coupon = new global::Event.Entity.Entity.Coupon.Coupon { Number = num.ToString(), Price = model.Price, Status = model.Status, CouponCategoryId = model.CouponCategoryId }; if (_couponService.Create(coupon) != null) { return(PageHelper.toJson(PageHelper.ReturnValue(true, "数据添加成功"))); } return(PageHelper.toJson(PageHelper.ReturnValue(false, "数据添加失败"))); }
public CouponEntity Create([FromBody] CouponEntity CouponEntity) { return(CouponService.Create(EmployeeEntity, CouponEntity)); }