internal static void DeleteFile(this IAssociateFile resource) { if (string.IsNullOrWhiteSpace(resource.FileName)) { return; } var path = GetServerPath(resource); DeleteFile(path, resource.FileName); }
public static string GetServerPath(this IAssociateFile assocFile) { const string activityPath = @"App_Data\TeachingResources\{0}\{1}.zip"; const string scenarioResourcePath = @"App_Data\Scenarios\{0}.zip"; const string prereadingPath = @"App_Data\PreReading\{0}.zip"; //if (string.IsNullOrEmpty(assocFile.FileName)) { return null; } Type t = System.Data.Entity.Core.Objects.ObjectContext.GetObjectType(assocFile.GetType()); //cover for dynamic proxies string returnVar; switch (t.Name) { case nameof(Activity): var a = (Activity)assocFile; returnVar = string.Format(activityPath, a.CourseActivityId, a.FileName); break; case nameof(ActivityDto): var ad = (ActivityDto)assocFile; returnVar = string.Format(activityPath, ad.CourseActivityId, ad.FileName); break; case nameof(ScenarioResource): var s = (ScenarioResource)assocFile; returnVar = string.Format(scenarioResourcePath, s.ScenarioId); break; case nameof(ScenarioResourceDto): var sd = (ScenarioResourceDto)assocFile; returnVar = string.Format(scenarioResourcePath, sd.ScenarioId); break; case nameof(Room): case nameof(RoomDto): returnVar = @"Content\images\roomMaps\" + assocFile.Id + Path.GetExtension(assocFile.FileName); break; case nameof(Institution): case nameof(InstitutionDto): returnVar = @"Content\images\institutions\" + assocFile.Id + Path.GetExtension(assocFile.FileName); break; case nameof(CourseType): case nameof(CourseTypeDto): returnVar = @"App_Data\Templates\Certificates\" + (string.IsNullOrEmpty(assocFile.FileName) ? "Generic Certificate Template.pptx" : assocFile.Id + Path.GetExtension(assocFile.FileName)); break; case nameof(CandidatePrereading): var c = (CandidatePrereading)assocFile; returnVar = string.Format(prereadingPath, c.CourseTypeId); break; case nameof(CandidatePrereadingDto): var cd = (CandidatePrereadingDto)assocFile; returnVar = string.Format(prereadingPath, cd.CourseTypeId); break; default: throw new ArgumentException("unhandled type"); } return(HttpRuntime.AppDomainAppPath + returnVar); }