public async Task <IActionResult> Create(PromotionCreateRequest request) { if (ModelState.IsValid) { var result = await _promotionServive.Create(request); if (result.IsSuccessed == true) { TempData["result"] = "Create Success"; TempData["IsSuccess"] = true; } else { TempData["result"] = result.Message; TempData["IsSuccess"] = false; } return(RedirectToAction("Index", "promotion")); } else { TempData["IsSuccess"] = false; TempData["result"] = string.Join(" | ", ModelState.Values .SelectMany(v => v.Errors) .Select(e => e.ErrorMessage)); //ViewBag.IsSuccess = false; return(RedirectToAction("Index", "promotion")); } }
public bool Create(PromotionCreateRequest entity) { string description = entity.Description; DateTime beginDate = entity.BeginDate; DateTime expiredDate = entity.ExpiredDate; if (!util.ValidRangeLengthInput(description, 1, 250) || beginDate == null || expiredDate == null || beginDate.CompareTo(expiredDate) >= 0) { return(false); } Promotion existed = _proRepo.GetAll() .FirstOrDefault(e => e.Description.Trim().ToLower().Equals(description.Trim().ToLower())); if (existed != null) { return(false); } Promotion newEntity = new Promotion(); newEntity.Description = description.Trim(); newEntity.BeginDate = beginDate; newEntity.BrandId = entity.BrandId; return(_proRepo.Create(newEntity)); }
public ActionResult <Promotion> PostPromotion(PromotionCreateRequest entity) { bool success = _proSer.Create(entity); if (success) { return(Ok(entity)); } return(Problem("Create failed!")); }
public async Task <IActionResult> Create(PromotionCreateRequest request) { if (ModelState.IsValid == false) { return(BadRequest(ModelState)); } var result = await _promotionService.Create(request); if (result.IsSuccessed == false) { return(BadRequest(result)); } return(Ok(result)); }
public async Task <ApiResult <bool> > Create(PromotionCreateRequest request) { var promotion = new Promotion() { Code = request.Code, DiscountPercent = request.DiscountPercent, DiscountAmount = request.DiscountAmount, FromDate = request.FromDate, ToDate = request.ToDate }; _context.Promotions.Add(promotion); return(await SaveChangeService.SaveChangeAsyncNotImage(_context)); }
public async Task <ApiResult <string> > Create(PromotionCreateRequest request) { var sections = _httpContextAccessor.HttpContext.Session.GetString("Token"); _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", sections); var json = JsonConvert.SerializeObject(request); var httpContent = new StringContent(json, Encoding.UTF8, "application/json"); var response = await _client.PostAsync($"/api/promotions", httpContent); var result = await response.Content.ReadAsStringAsync(); if (response.IsSuccessStatusCode) { return(JsonConvert.DeserializeObject <ApiResultSuccess <string> >(result)); } return(JsonConvert.DeserializeObject <ApiResultErrors <string> >(result)); }