public string createNewApp(App AppET, string rootPath) { if ((AppET.AppCategoryID == 0)||(AppET.AppIndustryID == 0)) { if (AppET.AppCategoryID == 0 && AppET.NewCategoryName != null) { //create new cat, and assign new cat id to appCategoryID field so db is updated with new cat AppCategory newCategoy = new AppCategory() { AppCategoryName = AppET.NewCategoryName }; cloudServerContext.AppCategories.Add(newCategoy); cloudServerContext.SaveChanges(); AppCategory appCategory = cloudServerContext.AppCategories.First(i => i.AppCategoryName == newCategoy.AppCategoryName); //assign newly created category to app AppET.AppCategoryID = appCategory.AppCatID; } if (AppET.AppIndustryID == 0 && AppET.NewIndustryName != null) { AppIndustry newIndustry = new AppIndustry() { AppIndustryName = AppET.NewIndustryName }; cloudServerContext.AppIndustries.Add(newIndustry); cloudServerContext.SaveChanges(); AppIndustry appIndustry = cloudServerContext.AppIndustries.First(i => i.AppIndustryName == newIndustry.AppIndustryName); AppET.AppIndustryID = appIndustry.AppIndustryID; } } cloudServerContext.Apps.Add(AppET); cloudServerContext.SaveChanges(); App updateApp = cloudServerContext.Apps.First(i => i.AppID == AppET.AppID); string appHashID = CalculateMD5Hash.GetHash(AppET.AppID.ToString()); updateApp.AppHash = appHashID; cloudServerContext.SaveChanges(); string pathString = Path.Combine(rootPath, "Apps/" + appHashID); Directory.CreateDirectory(pathString); string scriptFolder = Path.Combine(pathString, "Scripts"); Directory.CreateDirectory(scriptFolder); string stylesFolder = Path.Combine(pathString, "Styles"); Directory.CreateDirectory(stylesFolder); string imagesFolder = Path.Combine(pathString, "Images"); Directory.CreateDirectory(imagesFolder); File.WriteAllText(Path.Combine(pathString, "app.html"), "some text"); return appHashID; }
public static AppCategory ToDomainCategory(this AppCategoryModel inAppCat) { AppCategory appCat = new AppCategory() { AppCategoryName = inAppCat.AppCategoryName }; return appCat; }
public AppCategory createNewCategory(AppCategory appCat) { cloudServerContext.AppCategories.Add(appCat); cloudServerContext.SaveChanges(); AppCategory appCategory = cloudServerContext.AppCategories.First(i => i.AppCatID == appCat.AppCatID); return appCategory; }