예제 #1
0
        public IActionResult edit(string selectedSide, string selectedView, [FromBody] BannerImagesModel1 model1)
        {
            var message = 0;

            try
            {
                var data = db.BannerImages
                           .Where(x => x.Side.ToLower() == selectedSide.ToLower() && x.View.ToLower() == selectedView.ToLower() && x.IsActive == true)
                           .ToList();
                if (data != null)
                {
                    if (model1.ImageUrl1 != null)
                    {
                        data[0].Url = model1.ImageUrl1;
                    }
                    if (model1.ImageUrl2 != null && data.Count == 2)
                    {
                        data[1].Url = model1.ImageUrl2;
                    }
                    if (model1.ImageUrl3 != null && data.Count == 3)
                    {
                        data[2].Url = model1.ImageUrl3;
                    }
                    if (model1.ImageUrl4 != null && data.Count == 4)
                    {
                        data[3].Url = model1.ImageUrl4;
                    }
                    db.SaveChanges();
                    message = 1;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(Ok(message));
        }
예제 #2
0
        public async Task <IActionResult> uploadFile2([FromBody] BannerImagesModel1 model1)
        {
            var i       = 0;
            var message = 0;

            if (model1 != null)
            {
                if (model1.Position.Count == 1)
                {
                    var check = db.BannerImages
                                .Where(x => x.IsActive == true &&
                                       x.View.ToLower() == model1.view.FirstOrDefault().ToLower() &&
                                       x.Side.ToLower() == model1.side.FirstOrDefault().ToLower() &&
                                       x.Position == model1.Position[0]).FirstOrDefault();
                    if (check != null)
                    {
                        check.IsActive = false;
                        db.SaveChanges();
                    }
                }
                else if (model1.Position.Count == 2)
                {
                    var check = db.BannerImages
                                .Where(x => x.IsActive == true &&
                                       x.View.ToLower() == model1.view.FirstOrDefault().ToLower() &&
                                       x.Side.ToLower() == model1.side.FirstOrDefault().ToLower() &&
                                       x.Position == model1.Position[0]).FirstOrDefault();
                    if (check != null)
                    {
                        check.IsActive = false;
                        db.SaveChanges();
                    }
                    check = db.BannerImages
                            .Where(x => x.IsActive == true &&
                                   x.View.ToLower() == model1.view.FirstOrDefault().ToLower() &&
                                   x.Side.ToLower() == model1.side.FirstOrDefault().ToLower() &&
                                   x.Position == model1.Position[1]).FirstOrDefault();
                    if (check != null)
                    {
                        check.IsActive = false;
                        db.SaveChanges();
                    }
                }
                else
                {
                    var check = db.BannerImages
                                .Where(x => x.IsActive == true
                                       // && x.View.ToLower() == model1.view.FirstOrDefault().ToLower()
                                       && x.Side.ToLower() == model1.side.FirstOrDefault().ToLower()
                                       ).ToList();
                    if (check != null)
                    {
                        foreach (var item in check)
                        {
                            item.IsActive = false;
                            db.SaveChanges();
                        }
                    }
                }
                //var check1 = db.BannerImages
                //       .Where(x => x.IsActive == true
                //         &&
                //        && x.View.ToLower() == model1.view.FirstOrDefault().ToLower()
                //      x.Side.ToLower() == model1.side.FirstOrDefault().ToLower()
                //     ).ToList();
                //if (check1 != null)
                //{

                //    foreach (var item in check1)
                //    {
                //        item.IsActive = false;
                //        db.SaveChanges();

                //    }
                //}

                if (model1.ImageUrl.Count > 0)
                {
                    foreach (var item in model1.ImageUrl)
                    {
                        if (item != null)
                        {
                            BannerImages bannerImages  = new BannerImages();
                            var          imageResponse = await S3Service.UploadObject(item);

                            var response = new JsonResult(new Object());
                            if (imageResponse.Success)
                            {
                                bannerImages.Image    = $"https://pistis.s3.us-east-2.amazonaws.com/{imageResponse.FileName}";;
                                bannerImages.Side     = model1.side.FirstOrDefault();
                                bannerImages.View     = model1.view.FirstOrDefault();
                                bannerImages.IsActive = true;

                                bannerImages.Position = model1.Position[i];
                                if (model1.Position[i] == 1)
                                {
                                    if (model1.ImageUrl1 != null && model1.ImageUrl1 != "")
                                    {
                                        bannerImages.Url = model1.ImageUrl1;
                                    }
                                }
                                if (model1.Position[i] == 2)
                                {
                                    if (model1.ImageUrl2 != null && model1.ImageUrl2 != "")
                                    {
                                        bannerImages.Url = model1.ImageUrl2;
                                    }
                                }
                                if (model1.Position[i] == 3)
                                {
                                    if (model1.ImageUrl3 != null && model1.ImageUrl3 != "")
                                    {
                                        bannerImages.Url = model1.ImageUrl3;
                                    }
                                }
                                if (model1.Position[i] == 4)
                                {
                                    if (model1.ImageUrl4 != null && model1.ImageUrl4 != "")
                                    {
                                        bannerImages.Url = model1.ImageUrl4;
                                    }
                                }

                                //     else if (i == 4)
                                //    {
                                //       if (model1.ImageUrl4 != null)
                                //        bannerImages.Url = model1.ImageUrl4;
                                //  }


                                i++;
                                db.BannerImages.Add(bannerImages);
                            }
                        }
                    }

                    message = 1;
                }
            }
            try
            {
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(Ok(message));
        }