Ejemplo n.º 1
0
 public ActionResult EditImage(long PackageID, long ImageID)
 {
     try
     {
         PackageImageSaveModel model = new PackageImageSaveModel();
         model.Package = objAPI.GetObjectByKey <PackageBriefInfo>("packageconfig", "PackageBrief", PackageID.ToString(), "id");
         model.Image   = objAPI.GetObjectByKey <utblTourPackageImage>("packageconfig", "imagebyid", ImageID.ToString(), "id");
         return(View(model));
     }
     catch (AuthorizationException)
     {
         TempData["ErrMsg"] = "Your Login Session has expired. Please Login Again";
         return(RedirectToAction("Login", "Account", new { Area = "" }));
     }
 }
Ejemplo n.º 2
0
        public ActionResult AddImage(PackageImageSaveModel model)
        {
            try
            {
                var validData = true;
                if (model.ImageStrs.PhotoThumb == null || model.ImageStrs.PhotoThumb == null)
                {
                    ModelState.AddModelError("PhotoStrs.PhotoThumb", "Select a Photo");
                    validData = false;
                }
                if (validData && ModelState.IsValid)
                {
                    Random rand          = new Random();
                    string name          = model.Image.PackageID + "_" + DateTime.Now.ToString("yyyyMMdd") + "_" + rand.Next(50) + ".webp";
                    string normal_result = SaveImage(model.ImageStrs.PhotoNormal, model.ImageStrs.PhotoThumb, name);
                    if (normal_result.Contains("Error"))
                    {
                        TempData["ErrMsg"] = normal_result;
                        model.Package      = objAPI.GetObjectByKey <PackageBriefInfo>("packageconfig", "PackageBrief", model.Image.PackageID.ToString(), "id");
                        return(View(model));
                    }
                    model.Image.PhotoNormalPath = FileUrl + "Photos/Normal/" + normal_result;
                    model.Image.PhotoThumbPath  = FileUrl + "Photos/Thumb/" + normal_result;

                    string jsonStr = JsonConvert.SerializeObject(model.Image);
                    string result  = objAPI.PostRecordtoApI("packageconfig", "saveimage", jsonStr);
                    if (!result.ToLower().Contains("error"))
                    {
                        TempData["ErrMsg"] = "New Photo Added";
                        return(RedirectToAction("images", "tourpackage", new { Area = "Admin", id = model.Image.PackageID }));
                    }
                    TempData["ErrMsg"] = result;
                    DeleteFile(name);
                }
                model.Package = objAPI.GetObjectByKey <PackageBriefInfo>("packageconfig", "PackageBrief", model.Image.PackageID.ToString(), "id");
                return(View(model));
            }
            catch (AuthorizationException)
            {
                TempData["ErrMsg"] = "Your Login Session has expired. Please Login Again";
                return(RedirectToAction("Login", "Account", new { Area = "" }));
            }
        }