public ActionResult CreateProcess(FormCollection frm, HttpPostedFileBase[] ImagePath)
        {
            int kt = 0;
            try
            {
                foreach (HttpPostedFileBase file in ImagePath)
                {
                    /*Geting the file name*/
                    string filename = System.IO.Path.GetFileName(file.FileName);
                    /*Saving the file in server folder*/
                    file.SaveAs(Server.MapPath(@"~/Content/ImageUpload/" + filename));
                    string filepathtosave = "Content/ImageUpload/" + filename;

                    Nullable<int> isTopicImg = null;

                    Nullable<int> proId = null;
                    if (frm["ProgramId"] != "")
                    {
                        proId = int.Parse(frm["ProgramId"]);
                        List<ImageGallery> lsImg = ImageGalleryBusiness.GetImageTopic((int)proId);
                        if (lsImg.Count == 0)//if program doesn't has any image then set topic image =1
                        {
                            isTopicImg = 1;
                        }
                    }

                    Models.ImageGallery ad = new Models.ImageGallery()
                    {
                        ImagePath = filepathtosave,
                        ProgramId = proId,
                        IsTopicImage = isTopicImg,
                        Description = frm["Description"]
                    };

                    int check = ImageGalleryBusiness.AddImageGallery(ad);
                    if (check > 0)
                    {
                        kt++;
                    }
                }

            }
            catch
            {
                kt = 0;
            }

            if (kt == ImagePath.Count())
            {
                return RedirectToAction("Index", "ImageGallery", new { add = "success" });
            }
            else
            {
                return RedirectToAction("Index", "ImageGallery", new { add = "error" });
            }
        }
        public static int AddImageGallery(ImageGallery ad)
        {
            int ins = 0;
            try
            {
                ins = DataAccessLayer.ImageGalleryDA.AddImage(ad);
            }
            catch (Exception)
            {
                return 0;
            }

            return ins;
        }
        public static int AddSlideImage(ImageGallery ad)
        {
            int ins = 0;
            try
            {
                int? maxPos = GetMaxPosition();
                if (maxPos == null)
                {
                    ad.PositionInSilde = 1;
                }
                else
                {
                    ad.PositionInSilde = maxPos + 1;
                }

                ins = DataAccessLayer.ImageGalleryDA.AddImage(ad);
            }
            catch (Exception)
            {
                return 0;
            }

            return ins;
        }
        private static List<ImageGallery> AddImageGalleryToList2(DataTable dt, string flag)
        {
            List<ImageGallery> ls = new List<ImageGallery>();
            try
            {
                if (flag == "getImageProgram")
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        ImageGallery ad = new ImageGallery()
                        {

                            ProgramId = int.Parse(dt.Rows[i]["ProgramId"].ToString()),
                            ProgramName = dt.Rows[i]["Name"].ToString(),
                            TotalImage = int.Parse(dt.Rows[i]["TotalImage"].ToString()),
                        };

                        ls.Add(ad);
                    }
                }
                else
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        ImageGallery ad = new ImageGallery()
                        {
                            ProgramId = int.Parse(dt.Rows[i]["ProgramId"].ToString()),
                            ProgramName = dt.Rows[i]["Name"].ToString(),
                            ImagePath = dt.Rows[i]["ImagePath"].ToString()
                        };

                        ls.Add(ad);
                    }
                }

            }
            catch (Exception)
            {
                return new List<ImageGallery>();
            }
            return ls;
        }
        private static List<ImageGallery> AddImageGalleryToList(DataTable dt, string flag)
        {
            List<ImageGallery> ls = new List<ImageGallery>();
            try
            {

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    Nullable<int> proId = null;
                    Nullable<int> isTopicImg = null;
                    Nullable<int> isSlideImg = null;
                    Nullable<int> position = null;
                    if (dt.Rows[i]["ProgramId"].ToString() != "")
                    {
                        proId = int.Parse(dt.Rows[i]["ProgramId"].ToString());
                    }
                    if (dt.Rows[i]["IsTopicImage"].ToString() != "")
                    {
                        isTopicImg = int.Parse(dt.Rows[i]["IsTopicImage"].ToString());
                    }
                    if (dt.Rows[i]["IsSlideImage"].ToString() != "")
                    {
                        isSlideImg = int.Parse(dt.Rows[i]["IsSlideImage"].ToString());
                    }
                    if (dt.Rows[i]["PositionInSlide"].ToString() != "")
                    {
                        position = int.Parse(dt.Rows[i]["PositionInSlide"].ToString());
                    }

                    if (flag == "gallery")
                    {
                        ImageGallery ad = new ImageGallery()
                        {
                            Id = int.Parse(dt.Rows[i]["Id"].ToString()),
                            ProgramId = proId,
                            ProgramName = dt.Rows[i]["Name"].ToString(),
                            ImagePath = dt.Rows[i]["ImagePath"].ToString(),
                            Description = dt.Rows[i]["Description"].ToString(),
                            IsTopicImage = isTopicImg,
                            IsSildeImage = isSlideImg,
                            PositionInSilde = position,
                            IsDeleted = int.Parse(dt.Rows[i]["IsDeleted"].ToString()),

                        };

                        ls.Add(ad);

                    }
                    else
                    {
                        ImageGallery ad = new ImageGallery()
                        {
                            Id = int.Parse(dt.Rows[i]["Id"].ToString()),
                            ProgramId = proId,
                            ImagePath = dt.Rows[i]["ImagePath"].ToString(),
                            Description = dt.Rows[i]["Description"].ToString(),
                            IsTopicImage = isTopicImg,
                            IsSildeImage = isSlideImg,
                            PositionInSilde = position,
                            IsDeleted = int.Parse(dt.Rows[i]["IsDeleted"].ToString()),

                        };

                        ls.Add(ad);
                    }
                }
            }
            catch (Exception)
            {
                return new List<ImageGallery>();
            }
            return ls;
        }
        public static int EditImageSlide(ImageGallery ad)
        {
            int upt = 0;
            int check = 0;
            try
            {
                ImageGallery mOld = ImageGalleryBusiness.GetImageGalleryById(ad.Id)[0];
                int? maxPos = GetMaxPosition();

                if (ad.PositionInSilde != null && ad.PositionInSilde!=mOld.PositionInSilde)
                {
                    if (maxPos == null)
                    {
                        ad.PositionInSilde = 1;
                    }
                    else
                    {
                        if (mOld.PositionInSilde != null)
                        {
                            if (ad.PositionInSilde >= maxPos)
                            {
                                UpdatePostionDesc((int)mOld.PositionInSilde);
                                ad.PositionInSilde = maxPos;
                            }
                            else
                            {
                                if (ad.PositionInSilde < mOld.PositionInSilde)
                                {
                                    UpdatePostion((int)ad.PositionInSilde, null, "asc");
                                    check = 1;
                                }
                                else
                                {
                                    UpdatePostion((int)ad.PositionInSilde, mOld.PositionInSilde, "desc");
                                }

                            }
                        }
                        else
                        {
                            if (ad.PositionInSilde > maxPos)
                            {
                                ad.PositionInSilde = maxPos + 1;
                            }
                            else
                            {
                                int kt = UpdatePostion((int)ad.PositionInSilde,null,"asc");
                            }
                        }
                    }
                }
                else if (ad.PositionInSilde == null && mOld.PositionInSilde != null)
                {
                    UpdatePostionDesc((int)mOld.PositionInSilde);
                }
                upt = DataAccessLayer.ImageGalleryDA.EditImage(ad);
                if (upt > 0 && check == 1)
                {
                    UpdatePostionDesc((int)mOld.PositionInSilde);
                }
            }
            catch (Exception)
            {
                return 0;
            }
            return upt;
        }
        public static int EditImageGallery(ImageGallery ad)
        {
            int upt = 0;
            try
            {
                List<ImageGallery> lsOld = ImageGalleryBusiness.GetImageGalleryById(ad.Id);
                ImageGallery imgOld = lsOld[0];
                if (imgOld.IsTopicImage == 1 && imgOld.ProgramId != ad.ProgramId)
                {
                    int kt = UpdateIsTopicImageForOldProgram((int)imgOld.ProgramId, imgOld.Id);
                }

                if (ad.ProgramId != null)
                {
                    List<ImageGallery> ls = ImageGalleryBusiness.GetImageTopic((int)ad.ProgramId);
                    if (ad.IsTopicImage == 1)
                    {
                        if (ls.Count > 0)
                        {
                            UpdateIsTopicImage((int)ad.ProgramId);
                        }
                    }
                    else
                    {
                        if (ls.Count == 0)
                        {
                            ad.IsTopicImage = 1;
                        }

                    }
                }

                upt = DataAccessLayer.ImageGalleryDA.EditImage(ad);
            }
            catch (Exception)
            {
                return 0;
            }
            return upt;
        }
        public ActionResult SlideEditProcess(FormCollection frm, HttpPostedFileBase file)
        {
            int kt = 0;
            try
            {
                string filepathtosave = "";
                if (file != null)
                {
                        /*Geting the file name*/
                        string filename = System.IO.Path.GetFileName(file.FileName);
                        /*Saving the file in server folder*/
                        file.SaveAs(Server.MapPath(@"~/Content/ImageUpload/Slider/" + filename));
                        filepathtosave = "Content/ImageUpload/Slider/" + filename;
                }
                else
                {
                    filepathtosave = frm["ImagePath"];
                }

                int? position = null;
                if (frm["PositionInSilde"].ToString() != "")
                {
                    position = int.Parse(frm["PositionInSilde"].ToString());
                }

                Models.ImageGallery ad = new Models.ImageGallery()
                {
                    Id=int.Parse(frm["Id"]),
                    ImagePath = filepathtosave,
                    IsSildeImage=1,
                    PositionInSilde=position,
                    Description = frm["Description"]
                };

                int check = ImageGalleryBusiness.EditImageSlide(ad);
                if (check > 0)
                {
                    kt++;
                }
            }
            catch
            {
                kt = 0;
            }

            if (kt >0)
            {
                return RedirectToAction("ListSlide", "ImageGallery", new { update = "success" });
            }
            else
            {
                return RedirectToAction("ListSlide", "ImageGallery", new { update = "error" });
            }
        }
        public ActionResult SlideCreateProcess(FormCollection frm, HttpPostedFileBase[] ImagePath)
        {
            int kt = 0;
            try
            {
                foreach (HttpPostedFileBase file in ImagePath)
                {
                    /*Geting the file name*/
                    string filename = System.IO.Path.GetFileName(file.FileName);
                    /*Saving the file in server folder*/
                    file.SaveAs(Server.MapPath(@"~/Content/ImageUpload/Slider/" + filename));
                    string filepathtosave = "Content/ImageUpload/Slider/" + filename;

                    Models.ImageGallery ad = new Models.ImageGallery()
                    {
                        ImagePath = filepathtosave,
                        IsSildeImage = 1,
                        Description = frm["Description"]
                    };

                    int check = ImageGalleryBusiness.AddSlideImage(ad);
                    if (check > 0)
                    {
                        kt++;
                    }
                }

            }
            catch
            {
                kt = 0;
            }

            if (kt == ImagePath.Count())
            {
                return RedirectToAction("ListSlide", "ImageGallery", new { add = "success" });
            }
            else
            {
                return RedirectToAction("ListSlide", "ImageGallery", new { add = "error" });
            }
        }
        public ActionResult EditProcess(int id, FormCollection frm)
        {
            int kt = 0;
            try
            {
                Nullable<int> isTopicImg = null;

                Nullable<int> proId = null;
                if (frm["ProgramId"] != "")
                {
                    proId = int.Parse(frm["ProgramId"]);
                }

                if (frm["cbIsTopicImage"].ToString().Contains("rmb"))
                {
                    isTopicImg = 1;
                }

                Models.ImageGallery ad = new Models.ImageGallery()
                {
                    Id = int.Parse(frm["Id"]),
                    ImagePath = frm["ImagePath"],
                    ProgramId = proId,
                    IsTopicImage = isTopicImg,
                    Description = frm["Description"]
                };

                int check = ImageGalleryBusiness.EditImageGallery(ad);
                if (check > 0)
                {
                    kt++;
                }
            }
            catch
            {
                kt = 0;
            }

            if (kt > 0)
            {
                return RedirectToAction("Index", "ImageGallery", new { update = "success" });
            }
            else
            {
                return RedirectToAction("Index", "ImageGallery", new { update = "error" });
            }
        }