예제 #1
0
        public ActionResult SetC(QuestionViewModel model)
        {
            HttpPostedFileBase imga = model.imga;
            HttpPostedFileBase imgb = model.imgb;
            HttpPostedFileBase imgc = model.imgc;
            HttpPostedFileBase imgd = model.imgd;
            HttpPostedFileBase imge = model.imge;
            var path = "";

            if (imga != null) // Image A
            {
                if (imga.ContentLength > 0)
                {
                    // Untuk Mengecek apakah file berformat gambar
                    if ((Path.GetExtension(imga.FileName).ToLower() == ".jpg") || (Path.GetExtension(imga.FileName).ToLower() == ".png") || (Path.GetExtension(imga.FileName).ToLower() == ".gif") || (Path.GetExtension(imga.FileName).ToLower() == ".jpeg"))
                    {
                        path = Path.Combine(Server.MapPath("~/Images"), imga.FileName);
                        imga.SaveAs(path);
                    }
                }
                model.imageA = imga.FileName;
            }
            if (imgb != null) // Image B
            {
                if (imgb.ContentLength > 0)
                {
                    // Untuk Mengecek apakah file berformat gambar
                    if ((Path.GetExtension(imgb.FileName).ToLower() == ".jpg") || (Path.GetExtension(imgb.FileName).ToLower() == ".png") || (Path.GetExtension(imgb.FileName).ToLower() == ".gif") || (Path.GetExtension(imgb.FileName).ToLower() == ".jpeg"))
                    {
                        path = Path.Combine(Server.MapPath("~/Images"), imgb.FileName);
                        imgb.SaveAs(path);
                    }
                }
                model.imageB = imgb.FileName;
            }
            if (imgc != null) //Image C
            {
                if (imgc.ContentLength > 0)
                {
                    // Untuk Mengecek apakah file berformat gambar
                    if ((Path.GetExtension(imgc.FileName).ToLower() == ".jpg") || (Path.GetExtension(imgc.FileName).ToLower() == ".png") || (Path.GetExtension(imgc.FileName).ToLower() == ".gif") || (Path.GetExtension(imgc.FileName).ToLower() == ".jpeg"))
                    {
                        path = Path.Combine(Server.MapPath("~/Images"), imgc.FileName);
                        imgc.SaveAs(path);
                    }
                }
                model.imageC = imgc.FileName;
            }
            if (imgd != null) //Image D
            {
                if (imgd.ContentLength > 0)
                {
                    // Untuk Mengecek apakah file berformat gambar
                    if ((Path.GetExtension(imgd.FileName).ToLower() == ".jpg") || (Path.GetExtension(imgd.FileName).ToLower() == ".png") || (Path.GetExtension(imgd.FileName).ToLower() == ".gif") || (Path.GetExtension(imgd.FileName).ToLower() == ".jpeg"))
                    {
                        path = Path.Combine(Server.MapPath("~/Images"), imgd.FileName);
                        imgd.SaveAs(path);
                    }
                }
                model.imageD = imgd.FileName;
            }
            if (imge != null) //Image E
            {
                if (imge.ContentLength > 0)
                {
                    // Untuk Mengecek apakah file berformat gambar
                    if ((Path.GetExtension(imge.FileName).ToLower() == ".jpg") || (Path.GetExtension(imge.FileName).ToLower() == ".png") || (Path.GetExtension(imge.FileName).ToLower() == ".gif") || (Path.GetExtension(imge.FileName).ToLower() == ".jpeg"))
                    {
                        path = Path.Combine(Server.MapPath("~/Images"), imge.FileName);
                        imge.SaveAs(path);
                    }
                }
                model.imageE = imge.FileName;
            }

            ResponseResult result = QuestionRepo.SetC(model);

            return(Json(new
            {
                success = result.Success,
                message = result.ErrorMessage,
                entity = result.Entity
            }, JsonRequestBehavior.AllowGet));
        }