Exemple #1
0
        public JsonResult DeleteAll()
        {
            try
            {
                string type = ((int)Session["Type"] != 2) ? "ScreenSaver" : "LockScreen";

                // Remove all images in ImagesUpload and Uploaded
                List <ImageModel> removeList = (List <ImageModel>)Session["Images"];
                foreach (var item in removeList.Where(x => x.Type == type).ToList())
                {
                    // Check if not exists other type
                    if (!removeList.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);
                        }
                    }
                }

                List <ImageModel> tempList = (List <ImageModel>)Session["Images"];
                tempList.RemoveAll(x => x.Type == type);
                Session["Images"] = tempList;
                //ReadWriteCSV.WriteCSV(new List<ImageModel>());
                ReadWriteCSV.WriteCSV(tempList);
                // Remove all schedule
                JobsSchedule.RemoveAllSchedule();
                Notification("Notify", "Remove all list images successfuly", MyConstants.NOTIFY_SUCCESS);
                return(Json(new { status = true }));
            }
            catch (Exception)
            {
                Notification("Error", "Remove all list images failure", MyConstants.NOTIFY_ERROR);
                return(Json(new { status = false }));

                throw;
            }
        }
Exemple #2
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
            }));
        }
Exemple #3
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() }));
            }
        }