public IActionResult Insert([FromBody] Invoice value) { // Maybe remove this? IEnumerable <Invoice> existing = _context.Invoices.Where(x => x.Number == value.Number); if (existing.Any()) { return(NotFound(new ApiError("There's already a record for an invoice with this number."))); } value.Id = 0; // Maybe remove this? IEnumerable <Client> items = _context.Clients.Where(x => x.Id == value.ClientId); if (!items.Any()) { return(NotFound(new ApiError("There's no client associated with that invoice."))); } value.Client = items.First(); value.ClientId = value.Client.Id; _context.Invoices.Add(value); _context.SaveChanges(); return(Ok(value)); }
public IActionResult Insert([FromBody] Client value) { value.Id = 0; _context.Clients.Add(value); _context.SaveChanges(); return(Ok(value)); }
public async Task <IActionResult> Register(RegisterViewModel model, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { var user = new User { UserName = model.Email, Email = model.Email }; var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { var userRole = new UserRole { CreateBy = "superadministrator", CreationDate = DateTime.Now, Role = model.Role, IdUser = user.Id }; _context.UserRole.Add(userRole); _context.SaveChanges(); _logger.LogInformation("User created a new account with password."); var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = Url.EmailConfirmationLink(user.Id.ToString(), code, Request.Scheme); await _emailSender.SendEmailConfirmationAsync(model.Email, callbackUrl); await _signInManager.SignInAsync(user, isPersistent : false); _logger.LogInformation("User created a new account with password."); return(RedirectToLocal(returnUrl)); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }