public async Task <IActionResult> Create(TaxiEntity taxiEntity) { if (ModelState.IsValid) { taxiEntity.Plaque = taxiEntity.Plaque.ToUpper(); _context.Add(taxiEntity); try { await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } catch (Exception ex) { if (ex.InnerException.Message.Contains("duplicate")) { ModelState.AddModelError(string.Empty, "Already exist a Taxi with the same Plaque."); } else { ModelState.AddModelError(string.Empty, ex.InnerException.Message); } } } return(View(taxiEntity)); }
public IActionResult Register() { var valid = true; string fullName = HttpContext.Request.Form["fullName"]; string email = HttpContext.Request.Form["email"]; string password = HttpContext.Request.Form["password"]; if (fullName.Length < 6 || email.Length < 6 || password.Length < 6 || fullName.Length > 30 || email.Length > 30 || password.Length > 30) { valid = false; } if (valid) { UserDetails user = new UserDetails { Name = fullName, Email = email, Password = password, }; _context.Add(user); _context.SaveChangesAsync(); } else { ViewData["message"] = "Username, Password Invalid."; return(View("Login-Register")); } return(RedirectToAction("Index", "Home")); }
public IActionResult AddEmployee(Employee emp) { if (!ModelState.IsValid) { return(View(emp)); } context.Add(emp); context.SaveChanges(); return(RedirectToAction("Index")); }
public IActionResult Create(Employee model) { if (!ModelState.IsValid) { return(View(model)); } context.Add(model); context.SaveChanges(); return(RedirectToAction("index")); }
public async Task <IActionResult> Create([Bind("CardID,type")] DiscountCard discountCard) { if (ModelState.IsValid) { _context.Add(discountCard); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(discountCard)); }
public async Task <IActionResult> Create([Bind("Id,Ten")] TheLoai theLoai) { if (ModelState.IsValid) { _context.Add(theLoai); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(theLoai)); }
public async Task <IActionResult> Create([Bind("categoryID,categoryName,Quantity")] Category category) { if (ModelState.IsValid) { _context.Add(category); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(category)); }
public async Task <IActionResult> Create([Bind("Id,Email,MatKhau,DiaChi")] NguoiDung nguoiDung) { if (ModelState.IsValid) { _context.Add(nguoiDung); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(nguoiDung)); }
public async Task <IActionResult> Create([Bind("AlunoId,Nome,Email,RA,DataCadastro")] Aluno aluno) { if (ModelState.IsValid) { _context.Add(aluno); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(aluno)); }
public async Task <IActionResult> Create([Bind("Id,Nome,Valor")] Produto produto) { if (ModelState.IsValid) { _context.Add(produto); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(produto)); }
public async Task <IActionResult> Create([Bind("id,name")] RequestCategory requestCategory) { if (ModelState.IsValid) { _context.Add(requestCategory); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(requestCategory)); }
public async Task <IActionResult> Create([Bind("BlocoId,Nome,Descricao")] Bloco bloco) { if (ModelState.IsValid) { _context.Add(bloco); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(bloco)); }
public async Task <IActionResult> Create([Bind("Id,Ip,Name,Age")] info info) { if (ModelState.IsValid) { _context.Add(info); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(info)); }
public async Task <IActionResult> Create([Bind("Id,Ten,CauTraLoi1,CauTraLoi2,CauTraLoi3,CauTraLoi4,TheLoaiId")] CauHoi cauHoi) { if (ModelState.IsValid) { _context.Add(cauHoi); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["TheLoaiId"] = new SelectList(_context.TheLoais, "Id", "Id", cauHoi.TheLoaiId); return(View(cauHoi)); }
public async Task <IActionResult> Create([Bind("Id,Ten,CauHoiThiId,NguoiDungId")] Thi thi) { if (ModelState.IsValid) { _context.Add(thi); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["NguoiDungId"] = new SelectList(_context.NguoiDungs, "Id", "DiaChi", thi.NguoiDungId); return(View(thi)); }
public async Task <IActionResult> Create([Bind("Id,Ten,CauHoiId")] DapAn dapAn) { if (ModelState.IsValid) { _context.Add(dapAn); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CauHoiId"] = new SelectList(_context.CauHoi, "Id", "Id", dapAn.CauHoiId); return(View(dapAn)); }
public async Task <IActionResult> Create([Bind("productID,Name,Price,Image,productDate,categoryID")] Product product) { if (ModelState.IsValid) { _context.Add(product); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["categoryID"] = new SelectList(_context.Items, "categoryID", "categoryName", product.categoryID); return(View(product)); }
public async Task <IActionResult> AddTodo([FromBody] Todo todo) { todo.CreatedOn = DateTime.Now; _context.Add(todo); if (await _context.SaveChangesAsync() > 0) { return(CreatedAtRoute(new { isSaved = true }, "Your todo is Successfully added")); } throw new Exception("Creating todo failed on save"); }
public async Task <IActionResult> Create([Bind("userID,FullName,DateOfBirth,cardID")] User user) { if (ModelState.IsValid) { _context.Add(user); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["cardID"] = new SelectList(_context.Cards, "CardID", "type", user.cardID); return(View(user)); }
public async Task <IActionResult> Create([Bind("Id,Ten,ThiId")] Diem diem) { if (ModelState.IsValid) { _context.Add(diem); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["ThiId"] = new SelectList(_context.This, "Id", "Ten", diem.ThiId); return(View(diem)); }
public async Task <IActionResult> Create([Bind("SalaId,Nome,BlocoId,Disponivel")] Sala sala) { if (ModelState.IsValid) { _context.Add(sala); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["BlocoId"] = new SelectList(_context.Bloco, "BlocoId", "BlocoId", sala.BlocoId); return(View(sala)); }
public async Task <IActionResult> Create([Bind("userID,AddressLine1,City,State,Country")] Address address) { if (ModelState.IsValid) { _context.Add(address); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["userID"] = new SelectList(_context.Users, "userID", "FullName", address.userID); return(View(address)); }
public async Task <IActionResult> Create([Bind("ID,userID,productID")] Basket basket) { if (ModelState.IsValid) { _context.Add(basket); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["productID"] = new SelectList(_context.Products, "productID", "Name", basket.productID); ViewData["userID"] = new SelectList(_context.Users, "userID", "FullName", basket.userID); return(View(basket)); }
public async Task <IActionResult> Create([Bind("ReservaId,Nome,SalaId,DataInicio,DataFim,AlunoId")] Models.Reserva reserva) { if (ModelState.IsValid) { _context.Add(reserva); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["AlunoId"] = new SelectList(_context.Aluno, "AlunoId", "AlunoId", reserva.AlunoId); ViewData["SalaId"] = new SelectList(_context.Sala, "SalaId", "SalaId", reserva.SalaId); return(View(reserva)); }
public async Task <IActionResult> Create([Bind("CauHoiId,ThiId,Ten")] CauHoiThi cauHoiThi) { if (ModelState.IsValid) { _context.Add(cauHoiThi); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CauHoiId"] = new SelectList(_context.CauHoi, "Id", "Ten"); ViewData["ThiId"] = new SelectList(_context.This, "Id", "Ten"); return(View(cauHoiThi)); }
public async Task <IActionResult> Create([Bind("id,name,contactNumber,category,text,date,status,operatorName")] Request request) { if (ModelState.IsValid) { request.date = DateTime.Now; request.status = "Зарегистрировано"; request.operatorName = CurrentUser.Name; _context.Add(request); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(request)); }
public async Task <IActionResult> Create([Bind("id,username,passwordHash,salt,role")] User user) { if (ModelState.IsValid) { string salt = Cryptography.GenerateSalt(); user.salt = salt; user.passwordHash = Cryptography.GetHash(user.passwordHash + salt); _context.Add(user); await _context.SaveChangesAsync(); return(RedirectToAction("Index", "Home")); } return(View(user)); }
public async Task <IActionResult> Create([Bind("Id,Title,Artist,FileName,StartTime,StopTime")] Song song) { if (ModelState.IsValid) { _context.Add(song); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } song.Position = _context.Songs.Count(); return(View(song)); }
public async Task CreateRequestForCommandAsync <T>(Guid id) { var exists = await ExistAsync(id); var request = exists ? throw new Exception($"Request with {id} already exists") : new IdempotencyTransactionLog() { Id = id, Name = typeof(T).Name, Time = DateTime.UtcNow }; _context.Add(request); await _context.SaveChangesAsync(); }
public void Create(T entity) { _context.Add(entity); Save(); }