예제 #1
0
        public async Task <IActionResult> Create(PromotionFormModel model)
        {
            try
            {
                FillPromotionFormModel(model);
                if (!this.ModelState.IsValid)
                {
                    return(this.View((object)model));
                }
                if (!DateTime.TryParseExact(model.DueDateStr, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime result))
                {
                    model.IsSuccess   = false;
                    model.FormMessage = "Geçerli bir tarih giriniz.";
                    return(this.View((object)model));
                }
                model.DueDate = result;
                if (model.DueDate < DateTime.Today)
                {
                    model.IsSuccess   = false;
                    model.FormMessage = "Son kullanım tarihi bugünden önce olamaz.";
                    return(this.View((object)model));
                }
                PromotionDTO promotionDTO = new PromotionDTO
                {
                    IsActive  = true,
                    Message   = model.Message,
                    DueDate   = model.DueDate,
                    UserId    = model.UserId,
                    PlaceId   = model.PlaceId,
                    CreatedBy = base.CurrentUser.FullName
                };
                if (base.CurrentUser.Role == UserRole.Dealer)
                {
                    model.PlaceId = (base.CurrentUser.PlaceId ?? 0);
                }
                Result <PromotionDTO> result2 = await _promotionService.AddPromotionAsync(promotionDTO);

                model.FormMessage = result2.FormMessage;
                model.IsSuccess   = result2.IsSuccess;
                if (model.IsSuccess)
                {
                    model.FormMessage = "İşleminiz başarılı bir şekilde gerçekleştirildi.";
                }
                return(this.View((object)model));
            }
            catch (Exception ex)
            {
                LoggerExtensions.LogError(_logger, ex, "Create Error", Array.Empty <object>());
                model.IsSuccess   = false;
                model.FormMessage = "İşleminiz gerçekleştirilemedi.";
                return(this.View((object)model));
            }
        }
예제 #2
0
        public async Task <ActionResult> CreateProductAsync([FromBody] Promotion promotion)
        {
            //if (ModelState.IsValid)
            //{
            if (promotion.StartDate >= promotion.EndDate)
            {
                _logger.LogError("CreateProductAsync {@promotion}.", promotion);
                return(BadRequest("结束时间不能小于开始时间"));
            }
            var result = await _promotionService.AddPromotionAsync(promotion);

            if (result.Id == 0)
            {
                _logger.LogError("CreateProductAsync {@result}.", result);
                return(BadRequest("Create Failed"));
            }
            _logger.LogInformation("CreateProductAsync Success {@result}.", result);
            return(CreatedAtAction(nameof(ItemByIdAsync), new { id = result.Id }, null));
            //}
        }