Beispiel #1
0
        public ActionResult Create(FormCollection collection, Banners banners, BannerInfo bannerInfo, HttpPostedFileBase uploadfile)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    var listTypes = _generalFunctions.GetListType("Banner Yeri");
                    var model     = new BannersVM
                    {
                        Banners    = new Banners(),
                        BannerInfo = new BannerInfo(),
                        ListType   = listTypes
                    };
                }

                banners.CreationDate = DateTime.Now;
                if (uploadfile != null)
                {
                    bannerInfo.Banner = uploadfile.FileName;
                }
                else
                {
                    bannerInfo.Banner = null;
                }
                _bannerService.Add(banners);
                int bannerID = banners.BannerID;

                //Bannerı kayıt edelim.
                if (bannerInfo.Banner != null && uploadfile != null)
                {
                    _generalFunctions.CreateDirectory(HttpContext.Server.MapPath("/Uploads/Banners/"), bannerID.ToString());
                    uploadfile.SaveAs(HttpContext.Server.MapPath("/Uploads/Banners/" + bannerID + "/" + uploadfile.FileName));
                }

                //Banner bilgilerini kayıt edelim.
                bannerInfo.BannerID   = bannerID;
                bannerInfo.LanguageID = 1;
                _bannerInfoService.Add(bannerInfo);

                TempData.Add("message", "Banner başarıyla eklendi.");

                return(RedirectToAction("index"));
            }
            catch (Exception ex)
            {
                TempData.Add("message", "Banner yüklenirken hata ile karşılaştı. Hata: " + ex.Message);
                return(View());
            }
        }
        public async Task <IActionResult> Post([FromBody] CreateBannerModel banner)
        {
            if (banner == null)
            {
                return(BadRequest());
            }

            var result = await _service.Add(banner);

            if (!result.Sucessful)
            {
                return(BadRequest(result));
            }

            return(Ok(result));
        }
Beispiel #3
0
        public async Task <JsonResult> Add([FromBody] Banner banner)
        {
            if (ModelState.IsValid)
            {
                var responseModel = await _bannerservice.Add(banner);

                return(new JsonResult(responseModel));
            }
            else
            {
                return(new JsonResult(new ResponseModel
                {
                    code = 400,
                    result = "参数验证失败"
                }));
            }
        }
Beispiel #4
0
        public HttpResponseMessage Create(HttpRequestMessage request, BannerViewModel bannerVm)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                if (!ModelState.IsValid)
                {
                    response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    var newBanner = new Banner();
                    newBanner.UpdateBanner(bannerVm);
                    _bannerService.Add(newBanner);
                    _bannerService.Save();

                    var responseData = Mapper.Map <Banner, BannerViewModel>(newBanner);
                    response = request.CreateResponse(HttpStatusCode.Created, responseData);
                }

                return response;
            }));
        }
        // POST: api/Banner
        public HttpResponseMessage Post([FromBody] AdminBannerVMInput AdminBannerVMInput)
        {
            try
            {
                //var mediaUrlName = banner.MediaUrl;
                //if (banner.MediaUrl != null)
                //    banner.MediaUrl = "/Content/UploadFiles/images/images/" + banner.MediaUrl;
                //else
                //    banner.MediaUrl = "/Content/UploadFiles/images/images/" + banner.MediaUrl;

                //banner.MediaThumbUrl = "/Content/UploadFiles/images/images/thumb_" + mediaUrlName;

                var mediaUrl      = "/Content/UploadFiles/images/images/" + AdminBannerVMInput.MediaUrl;
                var mediaThumbUrl = "/Content/UploadFiles/images/images/thumb_" + AdminBannerVMInput.MediaUrl;
                var linkUrl       = AdminBannerVMInput.LinkUrl;
                var description   = AdminBannerVMInput.Description;
                var zOrder        = AdminBannerVMInput.ZOrder;
                var bannerName    = AdminBannerVMInput.Name;

                var maxOrder = _bannerService.Entities.Where(b => b.Deleted == false).Max(b => b.ZOrder);

                var banner = new Banner();
                banner.Name         = bannerName;
                banner.ZOrder       = maxOrder + 1;
                banner.Status       = true;
                banner.Deleted      = false;
                banner.CreatedById  = _userId;
                banner.ModifiedById = _userId;

                _bannerService.Add(banner);


                var justAddedBannerId    = _bannerService.Entities.Max(b => b.Id);
                var bannerMappingsModels = new List <BannerMapping>()
                {
                    new BannerMapping()
                    {
                        BannerId    = justAddedBannerId, LanguageId = 129, Status = true,
                        Name        = banner.Name, Description = description, Deleted = false,
                        MediaUrl    = mediaUrl, MediaThumbUrl = mediaThumbUrl, LinkUrl = linkUrl,
                        CreatedById = _userId, ModifiedById = _userId,
                    },
                    new BannerMapping()
                    {
                        BannerId    = justAddedBannerId, LanguageId = 29, Status = true,
                        Name        = "", Description = "", Deleted = false,
                        MediaUrl    = mediaUrl, MediaThumbUrl = mediaThumbUrl, LinkUrl = linkUrl,
                        CreatedById = _userId, ModifiedById = _userId
                    }
                };
                foreach (var bm in bannerMappingsModels)
                {
                    _bannerMappingService.Add(bm);
                }

                var responseMessage = new { message = "Thêm thành công!" };
                return(Request.CreateResponse(HttpStatusCode.OK, responseMessage));
            }
            catch (Exception)
            {
                var responseMessage = new { message = "Lỗi! Vui lòng thử lại sau!" };
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, responseMessage));

                throw;
            }
        }