Ejemplo n.º 1
0
        public JsonResult Delete(long id)
        {
            var    sessionCart = (List <ImageModel>)Session["Images"];
            string type        = ((int)Session["Type"] != 2) ? "ScreenSaver" : "LockScreen";

            // Remove that images: all information
            foreach (var item in sessionCart.Where(x => x.ID == id).ToList())
            {
                // Check if not exists other type
                if (!sessionCart.Exists(x => x.Type != type && x.Name == item.Name))
                {
                    System.IO.File.Delete(Path.Combine(Server.MapPath(pathTempImages), item.Name));
                    System.IO.File.Delete(Path.Combine(pathImages, item.Name));
                }

                // Remove active images
                if (item.TimeFrom < DateTime.Now && item.TimeTo > DateTime.Now)
                {
                    if (item.Type == "ScreenSaver")
                    {
                        RemoveActiveToDefault(pathScreenSaver, item.Name, pathDefaultScreenSaver);
                    }
                    else
                    {
                        RemoveActiveToDefault(pathLockScreen, "default.jpg", pathDefaultLockScreen);
                    }
                }
                // Remove all schedule apply
                JobsSchedule.RemoveAllSchedule();
            }

            sessionCart.RemoveAll(x => x.ID == id);
            Session["Images"] = sessionCart;
            ReadWriteCSV.WriteCSV(sessionCart);
            // Restart schedule apply after delete that item
            JobsSchedule.Start();
            if (sessionCart.Count == 0)
            {
                Session["Images"] = null;
            }
            return(Json(new
            {
                status = true
            }));
        }
Ejemplo n.º 2
0
        public JsonResult Done()
        {
            try
            {
                var imagesList = (List <ImageModel>)Session["Images"];
                if (imagesList != null)
                {
                    //Create list object - update url
                    List <ImageModel> newListImages = new List <ImageModel>();
                    newListImages = imagesList;
                    foreach (var item in newListImages)
                    {
                        if (!System.IO.File.Exists(pathImages + item.Name))
                        {
                            System.IO.File.Copy(Server.MapPath(pathTempImages) + item.Name, pathImages + item.Name);
                        }
                        item.Url = pathImages + item.Name;
                    }
                    //Save object to file.txt
                    ReadWriteCSV.WriteCSV(newListImages);
                    Session["Images"] = imagesList;
                    Notification("Notify", "Save list images successfuly", MyConstants.NOTIFY_SUCCESS);

                    // Start Schedule.
                    JobsSchedule.RemoveAllSchedule();
                    JobsSchedule.Start();
                    return(Json(new { status = true }));
                }
                else
                {
                    Notification("Error", "This list being empty", MyConstants.NOTIFY_ERROR);
                    return(Json(new { status = false }));
                }
            }
            catch (Exception e)
            {
                Notification("Error", "Have some error, Please contact with IT!", MyConstants.NOTIFY_ERROR);
                return(Json(new { status = e.ToString() }));
            }
        }