//check if all the images in one activity have been deleted
        bool check_images_exists_in_one_activity(int Id)
        {
            UserActivityImage userActivityImage = context.UserActivityImages.Find(Id);

            if (userActivityImage.image1 != null)
            {
                return(true);
            }

            if (userActivityImage.image2 != null)
            {
                return(true);
            }

            if (userActivityImage.image3 != null)
            {
                return(true);
            }

            if (userActivityImage.image4 != null)
            {
                return(true);
            }

            return(false);
        }
        /*--user activity image upload---*/
        void uploadActivityImages(IEnumerable <HttpPostedFileBase> photos, string UserName, string title)
        {
            int totolNumber = photos.Count();
            UserActivityImage userActivityImage = new UserActivityImage();

            userActivityImage.userName   = UserName;
            userActivityImage.title      = title;
            userActivityImage.uploadDate = DateTime.Now;
            string time    = DateTime.Now.Ticks.ToString();
            int    number  = 1;
            string dirUrl  = "~/Images/Uploads/UserActivityImages/" + UserName;
            string dirPath = Server.MapPath(dirUrl);

            // Check for Directory, If not exist, then create it
            if (!Directory.Exists(dirPath))
            {
                Directory.CreateDirectory(dirPath);
            }

            foreach (var photo in photos)
            {
                string extension = Path.GetExtension(photo.FileName).ToLower();
                var    fileName  = time + number + extension;
                var    path      = Path.Combine(Server.MapPath(dirUrl), fileName);
                photo.SaveAs(path);

                switch (number)
                {
                case 1:
                    userActivityImage.image1 = fileName;
                    break;

                case 2:
                    userActivityImage.image2 = fileName;
                    break;

                case 3:
                    userActivityImage.image3 = fileName;
                    break;

                default:
                    userActivityImage.image4 = fileName;
                    break;
                }
                number++;
            }

            context.UserActivityImages.Add(userActivityImage);
            context.SaveChanges();
        }
        public ActionResult deleteUserActivityImage(string UserName, int Id, int order)
        {
            UserActivityImage userActivityImage = context.UserActivityImages.Find(Id);

            if (userActivityImage != null)
            {
                switch (order)
                {
                case 1:
                    userActivityImage.image1 = null;
                    break;

                case 2:
                    userActivityImage.image2 = null;
                    break;

                case 3:
                    userActivityImage.image3 = null;
                    break;

                case 4:
                    userActivityImage.image4 = null;
                    break;

                default:
                    break;
                }
            }
            //check if all the images have been deleted
            if (!check_images_exists_in_one_activity(Id))
            {
                context.UserActivityImages.Remove(userActivityImage);
            }

            context.SaveChanges();
            return(RedirectToAction("UserProfile", new { UserName = UserName }));
        }
        /*--user activity image upload---*/
        void uploadActivityImages(IEnumerable<HttpPostedFileBase> photos, string UserName, string title)
        {
            int totolNumber = photos.Count();
            UserActivityImage userActivityImage = new UserActivityImage();
            userActivityImage.userName = UserName;
            userActivityImage.title = title;
            userActivityImage.uploadDate = DateTime.Now;
            string time = DateTime.Now.Ticks.ToString();
            int number = 1;
            string dirUrl = "~/Images/Uploads/UserActivityImages/" + UserName;
            string dirPath = Server.MapPath(dirUrl);
            // Check for Directory, If not exist, then create it
            if (!Directory.Exists(dirPath))
            {
                Directory.CreateDirectory(dirPath);
            }

            foreach (var photo in photos)
            {
                string extension = Path.GetExtension(photo.FileName).ToLower();
                var fileName = time + number + extension;
                var path = Path.Combine(Server.MapPath(dirUrl), fileName);
                photo.SaveAs(path);

                switch (number)
                {
                    case 1:
                        userActivityImage.image1 = fileName;
                        break;
                    case 2:
                        userActivityImage.image2 = fileName;
                        break;
                    case 3:
                        userActivityImage.image3 = fileName;
                        break;
                    default:
                        userActivityImage.image4 = fileName;
                        break;
                }
                number++;
            }

            context.UserActivityImages.Add(userActivityImage);
            context.SaveChanges();
        }