/DDB/Areas/Administration/Controllers/AdminController.cs
C# | 846 lines | 691 code | 148 blank | 7 comment | 168 complexity | d42bda56a4ea08b0e449d52c78dc92ac MD5 | raw file
Possible License(s): LGPL-2.1
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- using Core;
- using DevExpress.Web.Mvc;
- using DevExpress.Web.ASPxGridView;
- using System.Web.SessionState;
- using DDB.Areas.Administration.Models.Helper;
- using System.IO;
- using System.Net;
- using System.Xml.Linq;
- using System.Web.Configuration;
-
- namespace DDB.Areas.Administration.Controllers
- {
-
- [Authorize]
- public class AdminController : Controller
- {
-
- public AdminController()
- {
- ModelBinders.Binders.DefaultBinder = new DevExpressEditorsBinder();
- }
-
-
- //
- // GET: /Administration/Admin/
- public ActionResult Index()
- {
- return RedirectToAction("FrontPage", "Admin");
- }
-
- public ActionResult ListProjects()
- {
- Project _Project = new Project();
-
- var model = _Project.ListProjects(null).OrderBy(p => p.SortIndex).OrderByDescending(p => p.CRTime).ToList();
-
- return View(model);
- }
-
- public ActionResult ListProjectEdit()
- {
- Project _Project = new Project();
-
- var model = _Project.ListProjects(null).OrderBy(p => p.SortIndex).OrderByDescending(p => p.CRTime).ToList();
- return PartialView("ListProjects", model);
- }
-
- [HttpPost]
- public ActionResult ListProjectUpdate(Project _Project)
- {
-
- Project tmpProject = new Project(); // Old project
-
- if (ModelState.IsValid)
- {
- if (_Project.Slug.Contains(" "))
- {
- ModelState.AddModelError("Slug", "Slug contains empty space.");
- }
- else if (_Project.IsSlugUnique(_Project.Slug) == false && tmpProject.GetProjectByID(_Project.ID.Value).Slug != _Project.Slug)
- {
- ModelState.AddModelError("Slug", "Slug already exist.");
- }
- else
- {
- _Project.TSP_Projects(1, _Project.ID, _Project.Slug, null, _Project.Title, null, null, null, null, _Project.IsPublished, _Project.SortIndex,null,null);
-
- if (_Project.IsError)
- {
- ViewData["EditError"] = Resources.Fail;
- return PartialView("ListProjects", new Project().ListProjects(null));
- }
- }
- }
- else
- {
- ViewData["EditError"] = "Please, correct all errors.";
- }
-
- var model = _Project.ListProjects(null);
-
- return PartialView("ListProjects", model);
- }
-
- [HttpPost]
- public ActionResult ListProjectAdd(Project _Project)
- {
- if (ModelState.IsValid)
- {
- if (_Project.IsSlugUnique(_Project.Slug) == false)
- {
- ModelState.AddModelError("Slug", "Slug already exist.");
- }
- else if (_Project.Slug.Contains(" "))
- {
- ModelState.AddModelError("Slug", "Slug contains empty space.");
- }
- else
- {
- _Project.TSP_Projects(0, null, _Project.Slug, null, _Project.Title, null, null, null, null, _Project.IsPublished, _Project.SortIndex,null,null);
-
- if (_Project.IsError)
- {
- ViewData["EditError"] = Resources.Fail;
- return PartialView("ListProjects", new Project().ListProjects(null));
- }
- }
- }
- else
- {
- ViewData["EditError"] = "Please, correct all errors.";
- }
-
-
- var model = _Project.ListProjects(null);
- return PartialView("ListProjects", model);
- }
-
- public ActionResult ListProjectDelete(Project _Project)
- {
- if (_Project.ID >= 0)
- {
- DeleteProjectPictures(_Project);
-
- _Project.TSP_Projects(2, _Project.ID, null, null, null, null, null, null, null, null, null, null, null);
-
- if (_Project.IsError)
- {
- ViewData["EditError"] = Resources.Fail;
- return PartialView("ListProjects", new Project().ListProjects(null));
- }
- }
-
-
- var model = _Project.ListProjects(null);
- return PartialView("ListProjects", model);
- }
-
- private void DeleteProjectPictures(Project _Project)
- {
- var path = WebConfigurationManager.AppSettings["UploadPath"];
- var imgName = _Project.ListProjects(null).Where(p => p.ID == _Project.ID).Select(p => p.SmallImgName).FirstOrDefault();
-
- string delPath = Server.MapPath(path + "/" + imgName);
-
- if (System.IO.File.Exists(delPath))
- {
- System.IO.File.Delete(delPath);
- }
-
- ProjectAssets _ProjectAssets = new ProjectAssets();
-
- List<ProjectAssets> mediaImages = _ProjectAssets.ListProjectAssets(null).Where(p => p.ProjectID == _Project.ID).ToList();
- foreach (var item in mediaImages)
- {
- if (item.CodeVal == 2)
- {
- delPath = Server.MapPath(path + "/" + item);
-
- if (System.IO.File.Exists(delPath))
- {
- System.IO.File.Delete(delPath);
- }
- }
- }
- }
-
- [HttpGet]
- public ActionResult ListProjectDetails(string Slug)
- {
- if(Slug == null)
- {
- return RedirectToAction("ListProjects", "Admin");
- }
-
- Project _Project = new Project();
- _Project = _Project.ListProjects(null).SingleOrDefault(p => p.Slug == Slug);
- if (_Project == null)
- return HttpNotFound();
-
- ProjectAssets _ProjectAsset = new ProjectAssets();
- ViewBag.MediaItems = _ProjectAsset.ListProjectAssets(_Project.ID);
-
- Dictionary _Dictionary = new Dictionary();
- ViewBag.CategoryItems = _Dictionary.ListDictionary(1, 1);
-
- ProjectCategory _ProjectCategory = new ProjectCategory();
- ViewBag.SelectedCategoryItems = _ProjectCategory.ListProjectCategories(_Project.ID.Value).Select(x => x.CategoryID.Value).ToList();
-
- return View(_Project);
- }
-
- [HttpPost]
- [ValidateInput(false)]
- public ActionResult ListProjectDetails(Project _Project)
- {
-
- ProjectAssets _ProjectAsset = new ProjectAssets();
- ViewBag.MediaItems = _ProjectAsset.ListProjectAssets(_Project.ID);
-
-
- var allow = new string[] { ".jpg", ".gif", ".png" };
- var path = Server.MapPath(WebConfigurationManager.AppSettings["UploadPath"]);
- var guid = Guid.NewGuid().ToString();
-
- string ext = null;
-
- if (_Project.SmallImg == null && _Project.SmallImgName == null)
- {
- ModelState.AddModelError("SmallImg", "Image is required");
- }
- else if (_Project.SmallImg != null)
- {
- ext = Path.GetExtension(_Project.SmallImg.FileName).ToLower();
- if (!allow.Contains(ext))
- {
- ModelState.AddModelError("SmallImg", "unsupportied file extension: " + ext);
- }
-
- }
- if (_Project.ProjectCategories == null || !_Project.ProjectCategories.Any() )
- {
- ModelState.AddModelError("ProjectCategories", "Category is required");
- }
- if (_Project.BackgroundColor == null)
- {
- ModelState.AddModelError("BackgroundColor", "Theme is required");
- }
-
-
-
- if (ModelState.IsValid)
- {
- if (_Project.SmallImg != null)
- {
- ext = Path.GetExtension(_Project.SmallImg.FileName).ToLower();
-
- if (_Project.SmallImgName != null)
- {
- string delPath = path + "/" + _Project.SmallImgName;
- if (System.IO.File.Exists(delPath))
- {
- System.IO.File.Delete(delPath);
- }
- }
-
- path = Path.Combine(path, guid + ext);
- _Project.SmallImg.SaveAs(path);
- _Project.SmallImgName = guid + ext;
-
- }
-
-
- XElement X = new XElement("data",
- new XElement("items",
- _Project.ID == null ? null : new XElement("id", _Project.ID),
- _Project.Slug == null ? null : new XElement("slug", _Project.Slug),
- _Project.SmallImgName == null ? null : new XElement("small_img", _Project.SmallImgName),
- _Project.Title == null ? null : new XElement("title", _Project.Title),
- _Project.SmallText == null ? null : new XElement("small_text", _Project.SmallText),
- _Project.Summary == null ? null : new XElement("summary", _Project.Summary),
- _Project.Credits == null ? null : new XElement("credits", _Project.Credits),
- _Project.BackgroundColor == null ? null : new XElement("background_color", _Project.BackgroundColor),
- _Project.IsPublished == null ? null : new XElement("is_published", _Project.IsPublished),
- _Project.SortIndex == null ? null : new XElement("sort_index", _Project.SortIndex),
- _Project.Keywords == null ? null : new XElement("keywords", _Project.Keywords),
- _Project.Description == null ? null : new XElement("description", _Project.Description),
- new XElement("category",
- _Project.ProjectCategories.Select(c => new XElement("category_id", c))
- )
- )
- );
-
-
- _Project.TX_Projects(0, X);
- }
-
- Dictionary _Dictionary = new Dictionary();
- ViewBag.CategoryItems = _Dictionary.ListDictionary(1, 1);
- ViewBag.CodeVals = _Dictionary.ListDictionary(1, 2);
-
- List<int> EmptyCategories = new List<int>();
- ViewBag.SelectedCategoryItems = _Project.ProjectCategories ?? EmptyCategories;
-
- if (_Project.IsError)
- {
- ViewBag.TSP_Error = Resources.Fail;
- }
-
- return View(_Project);
- }
-
- [HttpPost]
- public JsonResult EditPicture(HttpPostedFileBase File)
- {
- return Json( "http://localhost:1325/Areas/Administration/Content/images/1/img2.jpg" );
- }
-
- [HttpPost]
- public ActionResult AddPicture(ProjectAssets _ProjectAsset)
- {
- var allow = new string[] { ".jpg", ".gif", ".png" };
- var path = Server.MapPath(WebConfigurationManager.AppSettings["UploadPath"]);
- var guid = Guid.NewGuid().ToString();
-
- Dictionary _Dictionary = new Dictionary();
-
- if (_ProjectAsset.imgFile != null)
- {
- string ext = Path.GetExtension(_ProjectAsset.imgFile.FileName).ToLower();
- if (!allow.Contains(ext))
- {
- return Json(new { errorMsg = "unsupportied file extension: " + ext });
- }
- else
- {
- path = Path.Combine(path, guid + ext);
- _ProjectAsset.imgFile.SaveAs(path);
- _ProjectAsset.Media = guid + ext;
-
- _ProjectAsset.TSP_ProjectAssets(0, _ProjectAsset.ID, _ProjectAsset.ProjectID, _Dictionary.GetDictionaryIDByCodeVal(2, _ProjectAsset.CodeVal), _ProjectAsset.GetNewPosition(_ProjectAsset.ProjectID), null, null, _ProjectAsset.Media);
- if (_ProjectAsset.IsError)
- {
- return Json(new { errorMsg = Resources.Fail });
- }
- return PartialView("_ListProjectDetailsPicture", new ProjectAssets { Media = _ProjectAsset.Media, ID = _ProjectAsset.ID });
- }
- }
-
- return Json(new {errorMsg = "There was some problem with file uploading !"});
- }
-
- [HttpPost]
- public JsonResult Sort(int[] ID, int[] Position, int ProjectID)
- {
- var _ProjectAsset = new ProjectAssets();
-
- for (int k = 0; k < ID.Length; k++)
- {
- _ProjectAsset.TSP_ProjectAssets(1, ID[k], ProjectID, null, Position[k], null, null, null);
- if (_ProjectAsset.IsError)
- {
- return Json(new { errorMsg = Resources.Fail });
- }
- }
- return null;
- }
-
- [HttpPost]
- [ValidateInput(false)]
- public ActionResult AddVideo(ProjectAssets _ProjectAsset)
- {
- Dictionary _Dictionary = new Dictionary();
-
- _ProjectAsset.TSP_ProjectAssets(0, _ProjectAsset.ID, _ProjectAsset.ProjectID, _Dictionary.GetDictionaryIDByCodeVal(2, _ProjectAsset.CodeVal), _ProjectAsset.GetNewPosition(_ProjectAsset.ProjectID), null, null, _ProjectAsset.Media);
-
- if (_ProjectAsset.IsError)
- {
- return Json(new { errorMsg = Resources.Fail });
- }
-
- return PartialView("_ListProjectDetailsVideo", new ProjectAssets { ID = _ProjectAsset.ID, Position = _ProjectAsset.Position, Media = _ProjectAsset.Media });
- }
-
- [HttpPost]
- [ValidateInput(false)]
- public ActionResult EditVideo(ProjectAssets _ProjectAsset)
- {
- _ProjectAsset.TSP_ProjectAssets(1, _ProjectAsset.ID, null, null, null, null, null, WebUtility.HtmlDecode(_ProjectAsset.Media));
- if (_ProjectAsset.IsError)
- {
- return Json(new { errorMsg = Resources.Fail });
- }
- return PartialView("_ListProjectDetailsVideo", new ProjectAssets { ID = _ProjectAsset.ID, Position = _ProjectAsset.Position, Media = _ProjectAsset.Media });
- }
-
- [HttpPost]
- [ValidateInput(false)]
- public ActionResult AddText(ProjectAssets _ProjectAsset)
- {
- Dictionary _Dictionary = new Dictionary();
-
- _ProjectAsset.TSP_ProjectAssets(0, _ProjectAsset.ID, _ProjectAsset.ProjectID, _Dictionary.GetDictionaryIDByCodeVal(2, _ProjectAsset.CodeVal), _ProjectAsset.GetNewPosition(_ProjectAsset.ProjectID), _ProjectAsset.Text, null, null);
- if (_ProjectAsset.IsError)
- {
- return Json(new { errorMsg = Resources.Fail });
- }
- return PartialView("_ListProjectDetailsText", new ProjectAssets { Text = _ProjectAsset.Text, ID = _ProjectAsset.ID });
- }
-
- [HttpPost]
- [ValidateInput(false)]
- public ActionResult EditText(ProjectAssets _ProjectAsset)
- {
- _ProjectAsset.TSP_ProjectAssets(1, _ProjectAsset.ID, null, null, _ProjectAsset.Position, WebUtility.HtmlDecode(_ProjectAsset.Text), null, null);
- if (_ProjectAsset.IsError)
- {
- return Json(new { errorMsg = Resources.Fail });
- }
- return PartialView("_ListProjectDetailsText", new ProjectAssets { Text = _ProjectAsset.Text, ID = _ProjectAsset.ID, Position = _ProjectAsset.Position });
- }
-
-
- [HttpPost]
- public JsonResult Delete(ProjectAssets _ProjectAsset)
- {
-
- var _Media = _ProjectAsset.ListProjectAssets(_ProjectAsset.ProjectID).Where(p => p.CodeVal == 2).Select(x => x.Media).FirstOrDefault();
-
- if (_Media != null)
- {
- var path = Server.MapPath(WebConfigurationManager.AppSettings["UploadPath"]);
- string delPath = path + "/" + _Media.ToString();
- if (System.IO.File.Exists(delPath))
- {
- System.IO.File.Delete(delPath);
- }
- }
- _ProjectAsset.TSP_ProjectAssets(2, _ProjectAsset.ID, null, null, null, null, null, null);
- if (_ProjectAsset.IsError)
- {
- return Json(new { errorMsg = Resources.Fail });
- }
- return Json(new { ID = _ProjectAsset.ID });
- }
-
-
- //========================= People ============================//
-
- public ActionResult ListPeoples()
- {
- People _People = new People();
-
- var model = _People.ListPeoples(null).OrderBy(p => p.SortIndex).OrderByDescending(p => p.CRTime).ToList();
- return View(model);
- }
-
- [HttpPost]
- public ActionResult ListPeopleEdit()
- {
- People _People = new People();
- var model = _People.ListPeoples(null).OrderBy(p => p.SortIndex).OrderByDescending(p => p.CRTime).ToList();
-
- return PartialView("ListPeoples", model);
- }
-
- [HttpPost]
- public ActionResult ListPeopleUpdate(People _People)
- {
-
- if (ModelState.IsValid)
- {
-
- _People.TSP_Peoples(1, _People.ID, _People.PeopleName, _People.Position, _People.ImgName,
- _People.MusicName, _People.SortIndex, _People.Theme, _People.IsPublished, _People.Slug);
- }
- else
- {
- ViewData["EditError"] = "Please, correct all errors.";
- }
-
- var model = _People.ListPeoples(null).OrderBy(p => p.SortIndex).OrderByDescending(p => p.CRTime).ToList();
- if(_People.IsError)
- {
- ViewData["EditError"] = Resources.Fail;
- }
- return PartialView("ListPeoples", model);
- }
-
- [HttpPost]
- public ActionResult ListPeopleAdd(People _People)
- {
- if (ModelState.IsValid)
- {
-
- _People.TSP_Peoples(0, _People.ID, _People.PeopleName, _People.Position, _People.ImgName,
- _People.MusicName, _People.SortIndex, _People.Theme, _People.IsPublished, _People.Slug);
-
- }
- else
- {
- ViewData["EditError"] = "Please, correct all errors.";
- }
-
- var model = _People.ListPeoples(null).OrderBy(p => p.SortIndex).OrderByDescending(p => p.CRTime).ToList();
- if (_People.IsError)
- {
- ViewData["EditError"] = Resources.Fail;
- }
- return PartialView("ListPeoples", model);
- }
-
- [HttpPost]
- public ActionResult ListPeopleDelete(People _People)
- {
- if (_People.ID > 0)
- {
- var path = Server.MapPath(WebConfigurationManager.AppSettings["UploadPath"]);
- var imgName = _People.ListPeoples(null).Where(p => p.ID == _People.ID).Select(p => p.ImgName).FirstOrDefault();
-
- string delPath = path + "/" + imgName;
-
- if (System.IO.File.Exists(delPath))
- {
- System.IO.File.Delete(delPath);
- }
-
- var musicName = _People.ListPeoples(null).Where(p => p.ID == _People.ID).Select(p => p.MusicName).FirstOrDefault();
-
- delPath = path + "/" + musicName;
- if (System.IO.File.Exists(delPath))
- {
- System.IO.File.Delete(delPath);
- }
-
- _People.TSP_Peoples(2, _People.ID, null, null, null, null, null, null, null, null);
- }
-
-
- var model = _People.ListPeoples(null).OrderBy(p => p.SortIndex).OrderByDescending(p => p.CRTime).ToList();
- if (_People.IsError)
- {
- ViewData["EditError"] = Resources.Fail;
- }
- return PartialView("ListPeoples", model);
- }
-
- [HttpGet]
- public ActionResult ListPeopleDetails(int? ID)
- {
- if(ID == null)
- {
- return RedirectToAction("ListPeoples", "Admin");
- }
- else if (ID > 0)
- {
- People _People = new People();
- _People = _People.ListPeoples(null).SingleOrDefault(p => p.ID == ID);
- if(_People == null)
- return HttpNotFound();
-
- Dictionary _Dictionary = new Dictionary();
- ViewBag.CategoryItems = _Dictionary.ListDictionary(1, 3);
-
- PeopleCategory _PeopleCategory = new PeopleCategory();
- ViewBag.SelectedCategoryItems = _PeopleCategory.ListPeopleCategories(_People.ID.Value).Select(p => p.CategoryID.Value).ToList();
-
- return View(_People);
- }
- return HttpNotFound();
- }
-
- [HttpPost]
- public ActionResult ListPeopleDetails(People _People)
- {
- var AllowIMG = new string[] { ".jpg", ".gif", ".png" };
- var AllowMusic = new string[] { ".mp3" };
-
- if (_People.ImgFile == null && _People.ImgName == null)
- {
- ModelState.AddModelError("ImgFile", "Image is required");
- }
- if (_People.MusicFile == null && _People.MusicName == null)
- {
- ModelState.AddModelError("MusicFile", "Music is required");
- }
- if (_People.Theme == null)
- {
- ModelState.AddModelError("Theme", "Theme is required");
- }
- if (_People.PeopleCategories == null)
- {
- ModelState.AddModelError("PeopleCategories", "Category is required");
- }
- if (_People.ImgFile != null)
- {
- string ext = Path.GetExtension(_People.ImgFile.FileName).ToLower();
- if (!AllowIMG.Contains(ext))
- {
- ModelState.AddModelError("ImgFile", "Unsupportied file extension: " + ext);
-
- }
- else if (_People.ImgFile.ContentLength > 2 * 1024 * 1024 * 8)
- {
- ModelState.AddModelError("ImgFile", "Size exceeds 2mb");
- }
- }
- if (_People.MusicFile != null)
- {
- string ext = Path.GetExtension(_People.MusicFile.FileName).ToLower();
-
- if (!AllowMusic.Contains(ext))
- {
- ModelState.AddModelError("MusicFile", "Unsupportied file extension: " + ext);
- }
- else if (_People.MusicFile.ContentLength > 10 * 1024 * 1024 * 8) // 10mb
- {
- ModelState.AddModelError("MusicFile", "Size exceeds 10mb");
- }
- }
-
-
- if(ModelState.IsValid)
- {
- //Upload Picture
- if (_People.ImgFile != null)
- {
- var guid = Guid.NewGuid().ToString();
- string ext = Path.GetExtension(_People.ImgFile.FileName).ToLower();
- var path = Server.MapPath(WebConfigurationManager.AppSettings["UploadPath"]);
-
- if (_People.ImgName != null)
- {
- string delPath = path + "/" + _People.ImgName;
- if (System.IO.File.Exists(delPath))
- {
- System.IO.File.Delete(delPath);
- }
- }
-
- path = Path.Combine(path, guid + ext);
-
- _People.ImgFile.SaveAs(path);
- _People.ImgName = guid + ext;
- }
- //Upload Music
- if (_People.MusicFile != null)
- {
- var guid = Guid.NewGuid().ToString();
- string ext = Path.GetExtension(_People.MusicFile.FileName).ToLower();
- var path = Server.MapPath(WebConfigurationManager.AppSettings["UploadPath"]);
-
- if (_People.MusicName != null)
- {
- string delPath = path + "/" + _People.MusicName;
- if (System.IO.File.Exists(delPath))
- {
- System.IO.File.Delete(delPath);
- }
- }
-
- path = Path.Combine(path, guid + ext);
-
- _People.MusicFile.SaveAs(path);
- _People.MusicName = guid + ext;
- }
-
- XElement X = new XElement("data",
- new XElement("items",
- _People.ID == null ? null : new XElement("id", _People.ID),
- _People.PeopleName == null ? null : new XElement("people_name", _People.PeopleName),
- _People.Position == null ? null : new XElement("position", _People.Position),
- _People.ImgName == null ? null : new XElement("img_name", _People.ImgName),
- _People.MusicName == null ? null : new XElement("music_name", _People.MusicName),
- _People.SortIndex == null ? null : new XElement("sort_index", _People.SortIndex),
- _People.Theme == null ? null : new XElement("theme", _People.Theme),
- _People.IsPublished == null ? null : new XElement("is_published", _People.IsPublished),
- _People.Slug == null ? null : new XElement("slug", _People.Slug),
-
- new XElement("category",
- _People.PeopleCategories.Select(c => new XElement("category_id", c))
- )
- )
- );
-
- _People.TX_Peoples(0, X);
-
- }
-
- Dictionary _Dictionary = new Dictionary();
- ViewBag.CategoryItems = _Dictionary.ListDictionary(1, 3);
-
- PeopleCategory _PeopleCategory = new PeopleCategory();
- List<int> EmptyCategories = new List<int>();
-
- ViewBag.SelectedCategoryItems = _People.PeopleCategories != null ? _People.PeopleCategories : EmptyCategories;
- if(_People.IsError)
- {
- ViewBag.TSP_Error = Resources.Fail;
- }
- return View(_People);
- }
- //=====================================refactor==============================
- public ActionResult ClientLogos()
- {
- var model = new Client().ListClients();
- return View(model);
- }
-
- [HttpGet]
- public ActionResult AddClientLogo()
- {
- var model = new Client();
- return View(model);
- }
-
- [HttpPost]
- public ActionResult AddClientLogo(Client Client)
- {
- if (Client.LogoFile == null)
- {
- ModelState.AddModelError("LogoFile", "Image is required");
- }
-
- if (Client.LogoFile != null)
- {
- var allow = new string[] { ".jpg", ".gif", ".png" };
- var path = Server.MapPath(WebConfigurationManager.AppSettings["UploadPath"]);
- var guid = Guid.NewGuid().ToString();
-
- string ext = Path.GetExtension(Client.LogoFile.FileName).ToLower();
- if (!allow.Contains(ext))
- {
- ModelState.AddModelError("LogoFile", "Unsupportied file extension: " + ext);
- }
- else if (Client.LogoFile.ContentLength > 10 * 1024 * 1024 * 8)
- {
- ModelState.AddModelError("LogoFile", "Size exceeds 10mb");
- }
- else
- {
- path = Path.Combine(path, guid + ext);
- Client.LogoFile.SaveAs(path);
- Client.LogoName = guid + ext;
- }
- }
-
- if(ModelState.IsValid)
- {
- Client.TSP_Clients(0, Client.ID, Client.LogoName, null, Client.Link);
-
- if (Client.IsError)
- {
- ViewBag.TSP_Error = Resources.Fail;
- return View(Client);
- }
-
- return RedirectToAction("ClientLogos", "Admin");
- }
-
- return View(Client);
- }
-
- [HttpGet]
- public ActionResult EditClientLogo(int? ID)
- {
- if(ID == null)
- {
- return RedirectToAction("ClientLogos", "Admin");
- }
- else if (ID > 0)
- {
- var model = new Client().ListClients().FirstOrDefault(c => c.ID == ID);
- if(model == null)
- return HttpNotFound();
- return View(model);
- }
-
- return HttpNotFound();
- }
-
- [HttpPost]
- public ActionResult EditClientLogo(Client Client)
- {
- if (Client.LogoFile == null && Client.LogoName == null)
- {
- ModelState.AddModelError("LogoFile", "Image is required");
- }
-
- if (Client.LogoFile != null)
- {
- var allow = new string[] { ".jpg", ".gif", ".png" };
- var path = Server.MapPath(WebConfigurationManager.AppSettings["UploadPath"]);
- var guid = Guid.NewGuid().ToString();
-
- string ext = Path.GetExtension(Client.LogoFile.FileName).ToLower();
- if (!allow.Contains(ext))
- {
- ModelState.AddModelError("LogoFile", "Unsupportied file extension: " + ext);
- }
- else if (Client.LogoFile.ContentLength > 10 * 1024 * 1024 * 8)
- {
- ModelState.AddModelError("LogoFile", "Size exceeds 10mb");
- }
- else
- {
- if (Client.LogoName != null)
- {
-
- string delPath = path + "/" + Client.LogoName;
- if (System.IO.File.Exists(delPath))
- {
- System.IO.File.Delete(delPath);
- }
- }
-
- path = Path.Combine(path, guid + ext);
- Client.LogoFile.SaveAs(path);
- Client.LogoName = guid + ext;
- }
- }
-
- if (ModelState.IsValid)
- {
- Client.TSP_Clients(1, Client.ID, Client.LogoName, null, Client.Link);
-
- if (Client.IsError)
- {
- ViewBag.TSP_Error = Resources.Fail;
- return View(Client);
- }
- }
-
- return View(Client);
- }
-
- public ActionResult DeleteClientLogo(int ID)
- {
-
- Client Client = new Client().ListClients().FirstOrDefault(c => c.ID == ID);
- var path = Server.MapPath(WebConfigurationManager.AppSettings["UploadPath"]);
-
- string delPath = path + "/" + Client.LogoName;
-
- if (System.IO.File.Exists(delPath))
- {
- System.IO.File.Delete(delPath);
- }
-
- Client.TSP_Clients(2, ID, null, null, null);
- if (Client.IsError)
- {
- TempData["TSP_Error"] = Resources.Fail;
- }
- return RedirectToAction("ClientLogos", "Admin");
- }
-
- //=======================================================================================
-
- }
- }