Ejemplo n.º 1
0
        public IActionResult SaveBanner()
        {
            int id = Request.Form["ID"].TryToInt(0);

            if (id > 0)
            {
                var info = _bannerService.GetBannerById(id);
                info.Name    = Request.Form["Name"].TryToString();
                info.BatchId = Request.Form["BatchId"].TryToInt(0);
                _bannerService.UpdateBanner(info);
                return(Json(new { code = 1, msg = "OK", id = info.Id }));
            }
            else
            {
                Banner bannerInfo = new Banner();
                bannerInfo.Name       = Request.Form["Name"].TryToString();
                bannerInfo.BatchId    = Request.Form["BatchId"].TryToInt(0);
                bannerInfo.CreateTime = DateTime.Now;
                id = _bannerService.AddBanner(bannerInfo);
                if (id > 0)
                {
                    return(Json(new { code = 1, msg = "OK", id = id }));
                }
                else
                {
                    return(Json(new { code = 0, msg = "保存失败" }));
                }
            }
        }
        public async Task <ICommandResult> Handle(BannerAddCommand mesage)
        {
            try
            {
                SystemDomains.Banner.Banner banner = new SystemDomains.Banner.Banner();
                banner.Add(mesage);
                await _bannerService.AddBanner(banner);

                await _eventSender.Notify(banner.Events);

                ICommandResult result = new CommandResult()
                {
                    Message  = "",
                    ObjectId = banner.Id,
                    Status   = CommandResult.StatusEnum.Sucess
                };
                return(result);
            }
            catch (Exception e)
            {
                e.Data["Param"] = mesage;
                ICommandResult result = new CommandResult()
                {
                    Message = e.Message,
                    Status  = CommandResult.StatusEnum.Fail
                };
                return(result);
            }
        }
Ejemplo n.º 3
0
        public ActionResult <Banner> Create(Banner banner)
        {
            var existinBanner = _bannerService.GetBannerById(banner.Id);

            if (existinBanner != null)
            {
                return(BadRequest("A Banner with same Id exists already"));
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _bannerService.AddBanner(banner);
            return(CreatedAtRoute("GetBanner", new { id = banner.Id.ToString() }, banner));
        }
Ejemplo n.º 4
0
        public ActionResult Create(BannerViewModel model, HttpPostedFileBase uploadFile)
        {
            if (ModelState.IsValid)
            {
                if (uploadFile != null && uploadFile.ContentLength > 0)
                {
                    ImageUpload imageUpload = new ImageUpload {
                        IsScale = false, SavePath = ImageUpload.LoadPathBanners
                    };
                    ImageResult imageResult = imageUpload.RenameUploadFile(uploadFile);

                    if (imageResult.Success)
                    {
                        // Add new image to database
                        var photo = new share_Images
                        {
                            ImageName = imageResult.ImageName,
                            ImagePath = imageResult.ImagePath
                        };
                        var imageId = _productService.AddImage(photo);
                        if (imageId != null)
                        {
                            // Add banner
                            model.ImageId = imageId.Value;
                            _bannerService.AddBanner(model);
                            return(RedirectToAction("Index"));
                        }
                    }
                    else
                    {
                        ViewBag.Error = imageResult.ErrorMessage;
                    }
                }
            }

            PopulateBannerTypesDropDownList();
            return(View(model));
        }
Ejemplo n.º 5
0
 public void Post(Banner banner)
 {
     _bannerService.AddBanner(banner).Wait();
 }