public static void InitializeSites(DbContextOptions <ApplicationDbContext> options) { using (var context = new ApplicationDbContext(options)) { var siteRepository = new SiteRepository(context); var repository = new Repository(context); if (!siteRepository.Any()) { siteRepository.Add (new Site { Name = "habr", Domain = "habr.com" }); siteRepository.Add (new Site { Name = "tut.by", Domain = "news.tut.by" }); siteRepository.Add (new Site { Name = "belta", Domain = "www.belta.by" }); repository.SaveChanges(); } } }
//CREATE SITE public Site CreateNewSite() { ISiteRepository repoSite = new SiteRepository(db); var site = new Site { CustomerId = 2, AddressId = 1, Name = "American Dad", Email = "*****@*****.**", HeadQuarters = false, Phone = "0396547891" }; var siteTwo = new Site { CustomerId = 2, AddressId = 2, Name = "The Simpsons", Email = "*****@*****.**", HeadQuarters = false, Phone = "0765481239" }; repoSite.Add(site); repoSite.Add(siteTwo); return(site); }
//public ActionResult Create(IEnumerable<HttpPostedFileBase> files) public ActionResult Create(int?contractID, IEnumerable <HttpPostedFileBase> files, string[] noteList, bool?IsFirstSave) { var site = repo.Add(UpdateModel, files, noteList); if (IsFirstSave.HasValue && IsFirstSave.Value) { return(RedirectToAction("Edit", new { id = site.ID })); } else { return(RedirectToAction("Index")); } }
public bool CreateSite(SiteViewModel viewModel, string userId, out string message, out string IdSite) { bool result = false; IdSite = string.Empty; message = string.Empty; //Todo var model = viewModel; string protocolSelecc = viewModel.protocoloSelected; model.CategoryTypeSelect = viewModel.categorySelected; model.URL = String.IsNullOrEmpty(model.URL) ? "-" : (String.IsNullOrEmpty(protocolSelecc) ? "https://" : protocolSelecc) + model.URL; //Create site CategoryRepository categoryRepository = new CategoryRepository(); var allCategory = categoryRepository.GetAll(); CategoryEntity _category = allCategory.FirstOrDefault(x => x.IdCategory == model.CategoryTypeSelect); AspNetUserRepository aspNetUserRepository = new AspNetUserRepository(); AspNetUserEntity _aspnetuser = aspNetUserRepository.GetAll().FirstOrDefault(x => x.Id == userId); SiteEntity _site = new SiteEntity { Name = model.Name, URL = model.URL, IdSite = Guid.NewGuid(), AspNetUsers_Id = userId, Verified = false, VerificationString = Guid.NewGuid().ToString(), RegistrationDate = DateTime.Now, IsActive = true }; SiteRepository siteRepository = new SiteRepository(); try { siteRepository.Add(_site); CategorySiteEntity categorySiteEntity = new CategorySiteEntity() { CATEGORY_IdCategory = _category.IdCategory, SITEs_IdSite = _site.IdSite }; CategorySiteRepository categorySiteRepository = new CategorySiteRepository(); categorySiteRepository.Add(categorySiteEntity); IdSite = _site.IdSite.ToString(); message = "Site created successfully"; result = true; } catch (Exception e) { message = "Error creating site"; } return(result); }