public async Task <IActionResult> Post(IdentityDocumentNewVm newId) { if (ModelState.IsValid && newId.File.Length > 0) { var party = _context.Party.Find(newId.PartyId); var idType = _context.IdentityDocumentType.Find(newId.TypeId); if (party != null && idType != null) { var fileName = "id." + Guid.NewGuid() + "." + newId.File.FileName.Substring(newId.File.FileName.LastIndexOf('.') + 1); var filePath = Path.Combine(_uploadPath, fileName); using (var fs = new FileStream(filePath, FileMode.Create)) { await newId.File.CopyToAsync(fs); } party.AddIdentityDocument(idType, newId.Num, newId.Effective, newId.Due, fileName); await _context.SaveChangesAsync(); return(Ok(new { fileName })); } } return(BadRequest()); }
public async Task <IActionResult> Post(PersonClientNewVm newPersonClient) { var sales = _context.SalesPerson.Find(newPersonClient.SalesPersonId); if (sales == null) { return(new BadRequestResult()); } Country nationality = null; if (newPersonClient.NationalityId.HasValue) { nationality = _context.Country.Find(newPersonClient.NationalityId); } var person = new Person(newPersonClient.Name, newPersonClient.OtherName, newPersonClient.Gender, newPersonClient.Tel, newPersonClient.Mobile, newPersonClient.Email, newPersonClient.BirthDate, nationality); var client = new Client(person); client.AddSalesPerson(sales); _context.Add(client); await _context.SaveChangesAsync(); return(Ok(client)); }