Example #1
0
        public async Task <IActionResult> Save([FromForm] BannerViewModel entity)
        {
            JsonModel json = new JsonModel()
            {
                Code = 200, Msg = "保存成功!"
            };

            try
            {
                if (entity == null)
                {
                    json.Code = 500;
                    json.Msg  = "Banner信息不能为空!";

                    return(Json(json));
                }

                if (entity.Id <= 0)
                {
                    await _bannerService.CreateBannerAsync(new Banner()
                    {
                        Description  = entity.Description,
                        ImageUrl     = entity.ImageUrl,
                        CreateDate   = DateTime.Now,
                        CreateUserId = Current.Id,
                        Order        = entity.Order,
                    });
                }
                else
                {
                    var model = await _bannerRepository.GetBannerByIdAsync(entity.Id);

                    model.Description  = entity.Description;
                    model.ImageUrl     = entity.ImageUrl;
                    model.UpdateDate   = DateTime.Now;
                    model.UpdateUserId = Current.Id;
                    model.Order        = entity.Order;

                    await _bannerService.UpdateBannerAsync(model);
                }
            }
            catch (Exception ex)
            {
                json.Code = 500;
                json.Msg  = $"保存异常!{ex.Message}";

                return(Json(json));
            }

            return(Json(json));
        }
Example #2
0
        public async Task <IActionResult> CreateBanner([FromBody] CreateBannerDto dto)
        {
            var result = await _bannerService.CreateBannerAsync(dto);

            return(new JsonResult(result));
        }