public async Task <ActionResult <ClientDto> > AddClient(ClientNewViewModel model) { var result = await _clientService.CreateAsync(_mapper.Map <ClientNewDto>(model)); return(new CreatedAtActionResult(nameof(GetClient), nameof(ClientsController), new { result.ClientId }, new ClientDto { ClientId = result.ClientId, PlainSecret = result.PlainSecret, ClientName = model.ClientName, Description = model.Description })); }
public async Task <IActionResult> Create(ClientNewViewModel clientNewViewModel) { var client = clientNewViewModel.c; var cs = clientNewViewModel.Inquiry; if (client.dob != null) { DateTime temp = client.dob ?? DateTime.Now; var tod = DateTime.Today; var age = tod.Year - temp.Year; if (temp.Date > tod.AddYears(-age)) { client.age = age--; } else { client.age = age; } } if (ModelState.IsValid) { _context.Add(client); await _context.SaveChangesAsync(); cs.ClientId = client.ClientId; _context.Add(cs); await _context.SaveChangesAsync(); clientNewViewModel.Note.ClientServiceId = cs.ClientServiceId; _context.Add(clientNewViewModel.Note); await _context.SaveChangesAsync(); TempData["Alert"] = String.Format("Created Client: {0} {1}", client.cfirst, client.clast); return(RedirectToAction("Edit", "Clients", new { id = client.ClientId })); } ViewData["ZcountyId"] = new SelectList(_context.Zcounty.OrderBy(m => m.county), "ZcountyId", "county", client.ZcountyId); ViewData["ZraceId"] = new SelectList(_context.Zrace.OrderBy(m => m.race), "ZraceId", "race", client.ZraceId); ViewData["ZinsuranceId"] = new SelectList(_context.Zinsurance.Where(m => m.active).OrderBy(m => m.insurance), "ZinsuranceId", "insurance", client.ZinsuranceId); return(View(clientNewViewModel)); }
public IActionResult Create() { ViewData["ZcountyId"] = new SelectList(_context.Zcounty.OrderBy(m => m.county), "ZcountyId", "county"); ViewData["ZraceId"] = new SelectList(_context.Zrace.OrderBy(m => m.race), "ZraceId", "race"); ViewData["ZschoolId"] = new SelectList(_context.Zschool.Where(m => m.active).OrderBy(m => m.displayname), "ZschoolId", "displayname"); ViewData["ZinsuranceId"] = new SelectList(_context.Zinsurance.Where(m => m.active).OrderBy(zi => zi.insurance), "ZinsuranceId", "insurance"); ViewData["ClientId"] = new SelectList(_context.Clients.OrderBy(c => c.name), "ClientId", "name"); ViewData["ServiceId"] = new SelectList(_context.Services.OrderBy(m => m.service_desc), "ServiceId", "service_desc"); ViewData["ZcaresreasonId"] = new SelectList(_context.Zcaresreason.OrderBy(m => m.caresreason), "ZcaresreasonId", "caresreason"); ViewData["ZhearaboutId"] = new SelectList(_context.Zhearabout.OrderBy(m => m.hearabout), "ZhearaboutId", "hearabout"); ViewData["ZinternalId"] = new SelectList(_context.Zinternal.Where(m => m.active).OrderBy(m => m.internal_type), "ZinternalId", "internal_type"); ViewData["ZinternalcategoryId"] = new SelectList(_context.Zinternalcategory.OrderBy(m => m.internalsubcat), "ZinternalcategoryId", "internalsubcat"); ViewData["ZlocationId"] = new SelectList(_context.Zlocation.OrderBy(m => m.location), "ZlocationId", "location"); ViewData["ZopotherId"] = new SelectList(_context.Zopother.OrderBy(m => m.opother), "ZopotherId", "opother"); ViewData["ZplatformId"] = new SelectList(_context.Zplatform.OrderBy(m => m.opplatform), "ZplatformId", "opplatform"); ViewData["ZprogramsId"] = new SelectList(_context.Zprograms.Where(m => m.active).OrderBy(m => m.program_desc), "ZprogramsId", "program_desc"); ViewData["ZreasonId"] = new SelectList(_context.Zreason.Where(m => m.active).OrderBy(m => m.final_reason), "ZreasonId", "final_reason"); ViewData["ZresourcereasonId"] = new SelectList(_context.Zresourcereason.OrderBy(m => m.resourceresult), "ZresourcereasonId", "resourceresult"); ViewData["ZsiteId"] = new SelectList(_context.Zsite.Where(m => m.active).OrderBy(m => m.site), "ZsiteId", "site"); ViewData["ZstatusId"] = new SelectList(_context.Zstatus.Where(m => m.active).OrderBy(m => m.inq_status), "ZstatusId", "inq_status"); ViewData["ZworkerId"] = new SelectList(_context.Zworker.Where(m => m.active).OrderBy(m => m.worker), "ZworkerId", "worker"); ClientNewViewModel clientNewViewModel = new ClientNewViewModel(); clientNewViewModel.c = new Client { }; clientNewViewModel.Inquiry = new ClientService { Client = clientNewViewModel.c }; clientNewViewModel.Inquiry.recdate = DateTime.Now; clientNewViewModel.Note = new Clineitem { ClientServiceId = clientNewViewModel.Inquiry.ClientServiceId }; clientNewViewModel.Note.ldate = DateTime.Now; return(View(clientNewViewModel)); }