private string SaveImageToDisk(LibraryFolder libFolder, HttpPostedFileBase httpPostedFileBase, string userfileName = null) { if (httpPostedFileBase.ContentLength > 0) { var appBasePath = ConfigurationManager.AppSettings["AppAssetPath"]; var appVirtuaPath = @"~\ResizedImages"; var orgPath = Path.Combine(libFolder.OrganizationId.ToString(), libFolder.FolderName); var assetPath = Path.Combine(appBasePath, orgPath); string fileName = null; if (userfileName == null) { fileName = Path.GetFileName(httpPostedFileBase.FileName); } else { string[] splitter = { "." }; var name = httpPostedFileBase.FileName.Split(splitter, StringSplitOptions.RemoveEmptyEntries); var extns = name[1]; fileName = string.Concat(userfileName, ".", extns); } var path = Path.Combine(assetPath, fileName); httpPostedFileBase.SaveAs(path); var request = System.Web.HttpContext.Current.Request; var urlHelper = new UrlHelper(request.RequestContext); var rootPath = System.Web.HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + urlHelper.Content("~/"); var appPath = appVirtuaPath.Replace(@"~\", ""); var virtualOrgPath = orgPath.Replace("\\", "/"); var servePath = @"{0}{1}/{2}/{3}".ToFormat(rootPath, appPath, virtualOrgPath, fileName); return servePath; } return null; }
private List<LibraryFolder> CreateDefaultFolder(ICollection<LibraryFolder> libraryFolders) { var libFldrs = libraryFolders.ToList(); var libFldr = libFldrs.FirstOrDefault(); libFldr.FolderName = "Assets"; libFldr.FolderHierarchy = "/"; libFldr.Createdate = DateTime.Now; libFldr.LibraryAssets = libFldrs.FirstOrDefault().LibraryAssets; var libraryDocFolder = new LibraryFolder() { FolderName = "Documents", FolderHierarchy = "Assets/Documents", Createdate = DateTime.Now, ParentFolderId = 1, LibraryAssets = new Collection<LibraryAsset>() }; //libFldrs.Add(libFldr); libFldrs.Add(libraryDocFolder); return libFldrs; }
public ActionResult Organization(OrganizationViewModel orgViewModel) { if (orgViewModel.OrganizationType != 0) ValidateViewModel(orgViewModel, orgViewModel.OrganizationType); else ModelState.AddModelError("OrganizationType", "Please select the organization type."); if (ModelState.IsValid) { if (orgViewModel.IsQuickView) { orgViewModel.NoOfQuickView = 1; orgViewModel.QuickViewEnd = false; } var mappedModel = Mapper.Map<OrganizationViewModel, Organization>(orgViewModel); mappedModel.CreatedDate = mappedModel.UpdatedDate = DateTime.Now; mappedModel.IsHomeOrg = false; mappedModel.CreatedBy = mappedModel.UpdatedBy = SessionContext.CurrentUser.Id; mappedModel.LibraryFolders = new List<LibraryFolder>(); var libFolder = new LibraryFolder(); var libAsset = GetLibraryAsset(orgViewModel.DisplayPicture); ICollection<LibraryAsset> libAssetsColl = new Collection<LibraryAsset>(); if (libAsset != null) libAssetsColl.Add(libAsset); libFolder.LibraryAssets = libAssetsColl; mappedModel.LibraryFolders.Add(libFolder); mappedModel.Active = true; var organizationModel = _wcfService.InvokeService<IUserService, Organization>((svc) => svc.AddOrganization(mappedModel)); if (organizationModel != null) { var lFolder = organizationModel.LibraryFolders.FirstOrDefault(x => x.FolderName == "Assets"); SaveImageToDisk(lFolder, orgViewModel.DisplayPicture); orgViewModel.CreationSuccessful = true; orgViewModel.Message = "{0} saved successfully.Your account will be activated for use after the approval process is completed by us.".ToFormat(organizationModel.OrganizationName); SessionContext.CurrentUser.OrganizationId = organizationModel.Id; } } else { ModelState.AddModelError("", "There was an error while saving. Please try again."); } return View(orgViewModel); }