public async Task <HttpResponseMessage> Edit(Guid code, BankIn bank) { var input = new BankEdit { Bank = bank, Code = code }; return(await this.ProcessActionAsync(input, this.bankService.Edit)); }
/// <summary> /// Validates the bank in. /// </summary> /// <param name="bank">The bank.</param> private static void ValidateBankIn(BankIn bank) { if (bank == null) { throw new ArgumentNullException(nameof(bank)); } if (string.IsNullOrEmpty(bank.Swift)) { throw new NullReferenceException("Swift must not be null."); } if (bank.Swift.Length > 50) { throw new Exception("Swift is longer then 50."); } if (string.IsNullOrEmpty(bank.Country)) { throw new NullReferenceException("Country must not be null."); } if (bank.Country.Length > 5) { throw new Exception("Country is longer then 5."); } if (string.IsNullOrEmpty(bank.Name)) { throw new NullReferenceException("Name must not be null."); } if (bank.Name.Length > 100) { throw new Exception("Name is longer then 100."); } if (bank.Name.Length < 2) { throw new Exception("Name is smaller then 2."); } if (string.IsNullOrEmpty(bank.Url)) { throw new NullReferenceException("Url must not be null."); } if (bank.Url.Length > 100) { throw new Exception("Url is longer then 250."); } }
/// <summary> /// The add. /// </summary> /// <param name="code"> /// The code. /// </param> /// <param name="bank"> /// The bank. /// </param> /// <returns> /// The <see cref="Task"/>. /// </returns> public async Task <int> Add(Guid code, BankIn bank) { var newBank = new BankEntity { Code = code, Swift = bank.Swift, Country = bank.Country, Name = bank.Name, Url = bank.Url }; this.context.Entry(newBank).State = EntityState.Added; var myint = await this.context.SaveChangesAsync(); return(myint); }
/// <summary> /// The edit. /// </summary> /// <param name="code"> /// The code. /// </param> /// <param name="bank"> /// The bank. /// </param> /// <returns> /// The <see cref="Task"/>. /// </returns> public async Task <int> Edit(Guid code, BankIn bank) { var newBank = new BankEntity { Code = code, Swift = bank.Swift, Country = bank.Country, Name = bank.Name, Url = bank.Url }; this.context.SeedAddOrUpdate(p => p.Code, p => new { p.Name, p.Swift, p.Country, p.Url, p.ChangeAt }, newBank); var myint = await this.context.SaveChangesAsync(); return(myint); }
/// <summary> /// The add. /// </summary> /// <param name="bank"> /// The bank. /// </param> /// <returns> /// The <see cref="Task"/>. /// </returns> /// <exception cref="Exception"> /// The exception. /// </exception> public async Task <Guid> Add(BankIn bank) { ValidateBankIn(bank); var existBySwift = await this.bankRepository.ExistsBySwift(bank.Swift); if (existBySwift) { throw new Exception($"Swift {bank.Swift} already exists."); } var code = Guid.NewGuid(); var result = await this.bankRepository.Add(code, bank); this.cacheProvider.Banks = null; return(result != 0 ? code : Guid.Empty); }
/// <summary> /// The edit. /// </summary> /// <param name="code"> /// The code. /// </param> /// <param name="bank"> /// The bank. /// </param> /// <returns> /// The <see cref="Task"/>. /// </returns> public Task <HttpResponseMessage> Edit(Guid code, BankIn bank) { throw new NotImplementedException(); }
////public Task<BankListResponse> Bankist() ////{ //// var context = CreateContextXml(); //// context.HttpMethod = HttpMethod.Post; context.ServiceMethod = ServiceMethod.List; //// //context.UrlPath = UrlPrefix + string.Format("/{0}/List", userId); //// //return await this.ExecuteSender<ListRequest, ListResponse>(request, context); //// return new Task<BankListResponse>(new Func<BankListResponse> {Method = { }}); /// <summary> /// The add. /// </summary> /// <param name="bank"> /// The bank. /// </param> /// <returns> /// The <see cref="Task"/>. /// </returns> public Task <HttpResponseMessage> Add(BankIn bank) { throw new NotImplementedException(); }
public async Task <HttpResponseMessage> Add(BankIn bank) { return(await this.ProcessActionAsync(bank, this.bankService.Add)); }