Example #1
0
 /// <summary>
 /// Change home page
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public ResponseModel ChangeHomePage(int id)
 {
     var response = new ResponseModel();
     var page = GetById(id);
     var homePage = GetHomePage();
     if (page != null)
     {
         if (page.Id != homePage.Id)
         {
             homePage.IsHomePage = false;
             page.IsHomePage = true;
             if (Update(homePage).Success)
             {
                 response = Update(page);
                 response.Message = string.Format(response.Success ?
                     _localizedResourceServices.T("AdminModule:::Pages:::Messages:::ChangeHomePageSuccessfully:::Change page {0} to home page successfully.")
                     : _localizedResourceServices.T("AdminModule:::Pages:::Messages:::ChangeHomePageFailure:::Change page {0} to home page failed. Please try again later.")
                     , page.Title);
             }
         }
         else
         {
             response.Success = true;
             response.Message =
                 string.Format(
                     _localizedResourceServices.T("AdminModule:::Pages:::Messages:::ChangeHomePageSuccessfully:::Change page {0} to home page successfully."),
                     page.Title);
         }
     }
     else
     {
         response.Success = false;
         response.Message = _localizedResourceServices.T("AdminModule:::Pages:::Messages:::ObjectNotFounded:::Page is not founded.");
     }
     return response;
 }
Example #2
0
 public JsonResult GetLogs(int id, int total, int index)
 {
     var model = _templateServices.GetLogs(id, total, index);
     var content = RenderPartialViewToString("_GetLogs", model);
     var response = new ResponseModel
     {
         Success = true,
         Data = new
         {
             model.LoadComplete,
             model.Total,
             content
         }
     };
     return Json(response);
 }
Example #3
0
        public ResponseModel Rename(string relativePath, string name, out string path)
        {
            var response = new ResponseModel
                {
                    Success = false
                };
            path = string.Empty;
            var status = MediaEnums.RenameStatusEnums.Failure;
            try
            {
                var physicalPath = HttpContext.Current.Server.MapPath(relativePath);
                var newPath = Directory.GetParent(physicalPath).FullName;

                // Check if current name and newname is the same
                var attPath = File.GetAttributes(physicalPath);
                if (attPath == FileAttributes.Directory)
                {
                    var diretoryInfo = new DirectoryInfo(physicalPath);
                    if (diretoryInfo.Name.Equals(name))
                    {
                        status = MediaEnums.RenameStatusEnums.Success;
                    }
                    else if (Directory.Exists(Path.Combine(newPath, name)))
                    {
                        status = MediaEnums.RenameStatusEnums.DuplicateName;
                    }
                }
                else
                {
                    var currentFileName = Path.GetFileName(physicalPath);
                    if (currentFileName != null && currentFileName.Equals(name))
                    {
                        status = MediaEnums.RenameStatusEnums.Success;
                    }
                    else if (File.Exists(Path.Combine(newPath, name)))
                    {
                        status = MediaEnums.RenameStatusEnums.DuplicateName;
                    }
                    else
                    {
                        var position = physicalPath.IndexOf(relativePath.Replace("/", "\\"), StringComparison.Ordinal);
                        if (position > 0)
                        {
                            var folder = ToRelativePath(newPath.Substring(position).Replace("\\", "/"));
                            newPath = Path.Combine(newPath, name);
                            Directory.Move(physicalPath, newPath);
                            path = string.Format("{0}/{1}", folder, name);
                            status = MediaEnums.RenameStatusEnums.Success;
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                Logger.Warn(exception);
                response.Message = exception.Message;
            }

            switch (status)
            {
                case MediaEnums.RenameStatusEnums.DuplicateName:
                    response.Message =
                        _localizedResourceServices.T(
                            "AdminModule:::Media:::RenameFolder:::Messages:::ExistingName:::The name of file/folder has already existed. Please rename and try again.");
                    break;
                case MediaEnums.RenameStatusEnums.Failure:
                    response.Message =
                        string.Format(_localizedResourceServices.T(
                            "AdminModule:::Media:::RenameFolder:::Messages:::RenameFailure:::Error while rename file/folder. Error Message: {0}. Please try again."), response.Message);
                    break;
                default:
                    response.Message =
                        _localizedResourceServices.T(
                            "AdminModule:::Media:::RenameFolder::::Messages:::RenameSuccess::Rename successfully.");
                    response.Success = true;
                    break;
            }
            return response;
        }
Example #4
0
        public ResponseModel MoveData(string source, string target, bool isCopy)
        {
            var response = new ResponseModel
                {
                    Success = false
                };
            var status = MediaEnums.MoveNodeStatusEnums.Success;
            try
            {
                var sourcePhysicalPath = HttpContext.Current.Server.MapPath(source);
                var targetPhysicalPath = HttpContext.Current.Server.MapPath(target);
                if (Directory.GetParent(sourcePhysicalPath).FullName.Equals(targetPhysicalPath))
                    status = MediaEnums.MoveNodeStatusEnums.MoveSameLocation;
                else
                {
                    // get the file attributes for file or directory
                    var attPath = File.GetAttributes(sourcePhysicalPath);
                    var attDestination = File.GetAttributes(targetPhysicalPath);

                    var fi = new FileInfo(sourcePhysicalPath);

                    if (attDestination != FileAttributes.Directory)
                    {
                        status = MediaEnums.MoveNodeStatusEnums.MoveNodeToFile;
                    }
                    else if (target.Contains(source))
                    {
                        status = MediaEnums.MoveNodeStatusEnums.MoveParentNodeToChild;
                    }
                    else
                    {
                        //detect whether its a directory or file
                        if ((attPath & FileAttributes.Directory) == FileAttributes.Directory)
                        {
                            //Move parent folder to children node
                            var targetFolder = string.Format("{0}/{1}", targetPhysicalPath, fi.Name);
                            MoveDirectory(sourcePhysicalPath, targetFolder, isCopy);
                        }
                        else
                        {
                            var fileName = Path.GetFileName(sourcePhysicalPath) ?? string.Empty;
                            fileName = GetRightFileNameToSave(targetPhysicalPath, fileName);
                            var targetFile = Path.Combine(targetPhysicalPath, fileName);
                            if (isCopy)
                            {
                                File.Copy(sourcePhysicalPath, targetFile);
                            }
                            else File.Move(sourcePhysicalPath, targetFile);
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                Logger.Warn(exception);
                status = MediaEnums.MoveNodeStatusEnums.Failure;
                response.Message = exception.Message;
            }
            switch (status)
            {
                case MediaEnums.MoveNodeStatusEnums.MoveParentNodeToChild:
                    response.Message =
                        _localizedResourceServices.T("AdminModule:::Media:::MoveData:::Messages:::MoveParentToChild:::Cannot move parent folder to child folder. Please try again.");
                    break;
                case MediaEnums.MoveNodeStatusEnums.MoveNodeToFile:
                    response.Message =
                        _localizedResourceServices.T("AdminModule:::Media:::MoveData:::Messages:::MoveItemToFile:::Cannot move item to file. Please try again.");
                    break;
                case MediaEnums.MoveNodeStatusEnums.MoveSameLocation:
                    response.Message =
                        _localizedResourceServices.T("AdminModule:::Media:::MoveData:::Messages:::MoveSameLocation:::Cannot move item in same location. Please try again.");
                    break;
                case MediaEnums.MoveNodeStatusEnums.Failure:
                    response.Message =
                        string.Format(
                            _localizedResourceServices.T("AdminModule:::Media:::MoveData:::Messages:::CreateFolderFailure:::There's an error: while create new folder. Error Message: {0}. Please try again."),
                            response.Message);
                    break;
                case MediaEnums.MoveNodeStatusEnums.Success:
                    response.Message =
                        string.Format(
                            _localizedResourceServices.T("AdminModule:::Media:::MoveData:::Messages:::MoveSuccessfully:::Move data successfully."),
                            response.Message);
                    response.Success = true;
                    break;
            }
            return response;
        }