public static void RegisterDadatabase() { var accountDbCommand = new AccountDbCommand(Constants.ConnectionString); var containerDbCommand = new ContainerDbCommand(Constants.ConnectionString); accountDbCommand.CreateAsync(PersonalStorageAccount).Wait(); accountDbCommand.CreateAsync(CommonStorageAccount).Wait(); containerDbCommand.SaveAsync(PersonalStorageContainer).Wait(); containerDbCommand.SaveAsync(CommonStorageContainer).Wait(); }
public async Task CreateTest() { var account = Account.NewAccount("Create Test", "Owner", StorageType.Common); await _dbCommand.CreateAsync(account); var registered = await _dbCommand.FindAsync(account.Id); registered.IsStructuralEqual(account); }
public async Task <ActionResult> Create(AccountCreateModel model) { var personalStorages = (await _storageDbCommand.GetListByOwnerAsync(User.Identity.Name, 0, int.MaxValue)).Where(x => x.StorageType == StorageType.Personal).ToArray(); if (!ModelState.IsValid) { model.PersonalSorages = personalStorages.Select(x => new SelectListItem { Text = x.Name, Value = x.Id }).ToList(); return(View("Create", model)); } if (Account.IsReservedName(model.Name)) { ModelState.AddModelError("Name", "この名前は使用できません。"); model.PersonalSorages = personalStorages.Select(x => new SelectListItem { Text = x.Name, Value = x.Id }).ToList(); return(View("Create", model)); } if (await _accountDbCommand.ExistsAsync(model.Name)) { ModelState.AddModelError("Name", "この名前はすでに使用されています。"); model.PersonalSorages = personalStorages.Select(x => new SelectListItem { Text = x.Name, Value = x.Id }).ToList(); return(View("Create", model)); } if (model.UsePersonalStorage && string.IsNullOrWhiteSpace(model.PersonalStorageId)) { ModelState.AddModelError("PersonalStorageId", @"個別ストレージを使用する場合は、ストレージを選択する必要があります。 選択リストに出てこない場合は、ストレージタブから新しい個別ストレージを登録してください。"); model.PersonalSorages = personalStorages.Select(x => new SelectListItem { Text = x.Name, Value = x.Id }).ToList(); return(View("Create", model)); } Account account; if (model.UsePersonalStorage) { var storage = personalStorages.FirstOrDefault(x => x.Id == model.PersonalStorageId); if (storage == null) { ModelState.AddModelError("PersonalStorageId", @"ストレージの選択が不正なようです。もう一度ストレージを選び直してください。"); model.PersonalSorages = personalStorages.Select(x => new SelectListItem { Text = x.Name, Value = x.Id }).ToList(); return(View("Create", model)); } account = Account.NewAccount(model.Name, User.Identity.Name, StorageType.Personal); account.Storages.Add(storage); Mapper.Map(model, account); } else { account = Account.NewAccount(model.Name, User.Identity.Name, StorageType.Common); Mapper.Map(model, account); } await _accountDbCommand.CreateAsync(account); return(RedirectToAction("Index")); }