public async Task <IActionResult> Create([Bind("IDIventaarioProdu,Cantidad,CantidadMinima")] InventarioProdu inventarioProdu) { if (ModelState.IsValid) { _context.Add(inventarioProdu); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(inventarioProdu)); }
public async Task <IActionResult> Create([Bind("IDEstado,Descripcion")] EstadoMesa estadoMesa) { if (ModelState.IsValid) { _context.Add(estadoMesa); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(estadoMesa)); }
public async Task <IActionResult> Create([Bind("TagId,TagName")] Tag tag) { if (ModelState.IsValid) { _context.Add(tag); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(tag)); }
public async Task <IActionResult> Create([Bind("IDReservaMesa,Nombre,Telefono,HoraReserva")] ReservaMesa reservaMesa) { if (ModelState.IsValid) { _context.Add(reservaMesa); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(reservaMesa)); }
public async Task <IActionResult> Create([Bind("IDGenero,Sigla,Descripcion")] Genero genero) { if (ModelState.IsValid) { _context.Add(genero); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(genero)); }
public async Task <IActionResult> Create([Bind("Id,Title,ReleaseDate,Genre,Price,Rating")] Movie movie) { if (ModelState.IsValid) { _context.Add(movie); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(movie)); }
public async Task <IActionResult> Create([Bind("IDRol,Descripcion,IDRelacion")] Rol rol) { if (ModelState.IsValid) { _context.Add(rol); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["IDRelacion"] = new SelectList(_context.Relaciones, "IDRelacion", "IDRelacion", rol.IDRelacion); return(View(rol)); }
public async Task <IActionResult> Create([Bind("IDOrden,FechaOrden,IDMesa")] Orden orden) { if (ModelState.IsValid) { _context.Add(orden); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["IDMesa"] = new SelectList(_context.Mesas, "IDMesa", "IDMesa", orden.IDMesa); return(View(orden)); }
public async Task <IActionResult> Create([Bind("IDIngrediente,Descripcion,IDInventarioIngre")] Ingrediente ingrediente) { if (ModelState.IsValid) { _context.Add(ingrediente); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["IDInventarioIngre"] = new SelectList(_context.InventarioIngredientes, "IDInventarioIngre", "IDInventarioIngre", ingrediente.IDInventarioIngre); return(View(ingrediente)); }
public async Task <IActionResult> Create([Bind("IDRelacion,Descripcion,IDPersona")] Relacion relacion) { if (ModelState.IsValid) { _context.Add(relacion); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["IDPersona"] = new SelectList(_context.Personas, "IDPersona", "IDPersona", relacion.IDPersona); return(View(relacion)); }
public async Task <IActionResult> Create([Bind("IDPersona,Cedula,Nombre,ApellidoPa,ApellidoMa,FechaNacimiento,FechaRegistro,Direccion,TelefonoCel,TelefonoDom,Usuario,Contraseña,IDGenero")] Persona persona) { if (ModelState.IsValid) { _context.Add(persona); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["IDGenero"] = new SelectList(_context.Generos, "IDGenero", "IDGenero", persona.IDGenero); return(View(persona)); }
public async Task <IActionResult> Create([Bind("IDProducto,Descripcion,Costo,Precio,IDCategoria,IDIventaarioProdu")] Producto producto) { if (ModelState.IsValid) { _context.Add(producto); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["IDCategoria"] = new SelectList(_context.Categorias, "IDCategoria", "IDCategoria", producto.IDCategoria); ViewData["IDIventaarioProdu"] = new SelectList(_context.InventarioProdus, "IDIventaarioProdu", "IDIventaarioProdu", producto.IDIventaarioProdu); return(View(producto)); }
public async Task <IActionResult> Create([Bind("IDMesa,NumeroMesa,IDEstado,IDReservaMesa")] Mesa mesa) { if (ModelState.IsValid) { _context.Add(mesa); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["IDEstado"] = new SelectList(_context.EstadoMesas, "IDEstado", "IDEstado", mesa.IDEstado); ViewData["IDReservaMesa"] = new SelectList(_context.ReservaMesas, "IDReservaMesa", "IDReservaMesa", mesa.IDReservaMesa); return(View(mesa)); }
public async Task SendMessage(string ArticleID, string Text) { var user = await _userManager.FindByNameAsync(Context.User.Identity.Name); Comment comment = new Comment(); comment.DateTime = DateTime.UtcNow; comment.User = user; comment.PostId = Int32.Parse(ArticleID); comment.Text = Text; _context.Add(comment); await _context.SaveChangesAsync(); await Clients.Group(ArticleID).SendAsync("ReceiveMessage", user.UserName, comment.Text, comment.DateTime); }
public async Task <IActionResult> SiteForm([Bind("SiteID,UserID,siteName,siteDescription,siteLandType,siteUses,siteWater,siteGas,siteOffroad,siteLong,siteLat,siteLevel")] Site site) { if (ModelState.IsValid) { var files = HttpContext.Request.Form.Files; foreach (var Image in files) { if (Image != null && Image.Length > 0) { var file = Image; var uploads = Path.Combine(_env.WebRootPath, "images\\sites"); if (file.Length > 0) { var fileName = ContentDispositionHeaderValue.Parse (file.ContentDisposition).FileName.Trim('"'); System.Console.WriteLine(fileName); using (var fileStream = new FileStream(Path.Combine(uploads, file.FileName), FileMode.Create)) { await file.CopyToAsync(fileStream); using (var image = new MagickImage(Path.Combine(uploads, file.FileName))) { image.Resize(100, 100); image.Strip(); image.Quality = 75; image.Write(Path.Combine(uploads, "thumb" + file.FileName)); } site.imglocation = file.FileName; site.imgthumblocation = "thumb" + file.FileName; } } } } _context.Add(site); await _context.SaveChangesAsync(); var site2 = await _context.Sites .SingleOrDefaultAsync(m => m.SiteID == site.SiteID); return(View("SiteView", site2)); } ViewData["UserID"] = new SelectList(_context.Users, "UserID", "userName"); return(View()); }
public async Task <IActionResult> Create([Bind("CommentID,cmtComment,cmtDate,UserID")] Comment comment, String site) { DateTime myDateTime = DateTime.Now; string sqlFormattedDate = myDateTime.ToString("yyyy-MM-dd HH:mm:ss.fff"); comment.cmtDate = myDateTime; Debug.WriteLine(comment.cmtDate); if (ModelState.IsValid) { _context.Add(comment); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View()); }
public async Task <IActionResult> Create([Bind("ClubID,ClubName,ClubDescription")] Club club, IFormFile uploadedFile) { if (ModelState.IsValid) { if (uploadedFile != null && uploadedFile.ContentType.ToLower().Contains("image")) { club.ClubImage = await _imageService.SaveImageAsync(uploadedFile, 0); _context.SaveChanges(); } else { ModelState.AddModelError("Image", "Некорректный формат"); return(View(club)); } _context.Add(club); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(club)); }
public IActionResult Post(ProductViewModel model) { //[api controller] atrubute change model binding source, from body for complex type and from route from simple types made default //[api controller] atrubute implement mehanizam that return 400 and all model state error wihtout ModelState.IsValid code part var product = _mapper.Map <Product>(model); var sup = _context.Suppliers.SingleOrDefault(s => s.SupplierId == model.SupplierId); if (sup == null) { return(BadRequest($"Supplier with id: {model.SupplierId} doesn't exists!")); } _context.Add(product); if (_context.SaveChanges() > 0) { return(CreatedAtAction("Get", new { id = product.ProductId }, _mapper.Map <ProductViewModel>(product))); } else { return(BadRequest()); } }
public async Task <IActionResult> Create( [Bind("Name, Email, BirthDate, Password, ConfirmPassword, City, State, Zip")] Profile profile) { /* Add Profile Action */ try { if (ModelState.IsValid) { _context.Add(profile); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } catch (DbUpdateException /* ex */) { //Log the error (uncomment ex variable name and write a log. ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists " + "see your system administrator."); } return(View()); }
async public static Task UploadPlayDeckAsync(List <Pokemon> playDeck, SiteContext db, HttpContext currentHttpContext) { User findUser = db.Users.ToList() .Where(u => u.Name == GetUser(currentHttpContext).Name).FirstOrDefault(); PokemonCard[] deleteCards = db.Cards.Where(card => card.User == findUser).ToArray(); db.RemoveRange(deleteCards); playDeck.ToList().ForEach(card => { if (card != null) { db.Add(new PokemonCard { User = findUser, Pokemon = card, SkillOne = card.ThisPokemonsSkills[0].Id, SkillTwo = card.ThisPokemonsSkills[1].Id }); } }); await db.SaveChangesAsync(); SetPlayDeck(findUser, db, currentHttpContext); }
public void Add(UserAccount account) { _context.Add(account); _context.SaveChanges(); }