public async Task <IActionResult> Create([Bind("IdPedido,FechaCompra,FechaLlegada,Estado,Importe,Descripcion")] Pedido pedido) { if (ModelState.IsValid) { _context.Add(pedido); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(pedido)); }
public async Task <IActionResult> Create([Bind("IdClaseGuarderia,HoraInicio,HoraFin,Fecha,Cupo,Duracion,Estado")] ClaseGuarderia claseGuarderia) { if (ModelState.IsValid) { _context.Add(claseGuarderia); await _context.SaveChangesAsync(); Thread.Sleep(1000); return(RedirectToAction(nameof(Index))); } return(View(claseGuarderia)); }
public async Task <ActionResult> Create([Bind("IdRecargaMV, IdMonedero, Monto")] RecargaMonederoV recargaMonederoV) { recargaMonederoV.Fecha = DateTime.Now; if (ModelState.IsValid) { using (var dbContextTransaction = _context.Database.BeginTransaction()) { try { var sumarmonto = _context.Monedero.Where(m => m.IdMonedero == recargaMonederoV.IdMonedero); if (sumarmonto != null) { foreach (var item in sumarmonto) { item.Saldo = ((float)item.Saldo + recargaMonederoV.Monto); } _context.Add(recargaMonederoV); dbContextTransaction.Commit(); await _context.SaveChangesAsync(); } } catch { dbContextTransaction.Rollback(); } } Thread.Sleep(2000); return(RedirectToAction(nameof(Index))); } return(RedirectToAction("Index")); }
public async Task <ApiResult <bool> > CreateAsync([FromBody] GymUser user) { ApiResult <bool> result = new ApiResult <bool>(); try { using (TransactionScope transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { user.PhoneNumber = ""; _context.Add(user); await _context.SaveChangesAsync(); transaction.Complete(); result.Value = true; result.Status = ApiResultStatus.SUCCESS; } } catch (Exception ex) { result.Status = ApiResultStatus.FAIL; } return(await Task.FromResult(result)); }
public async Task <IActionResult> Create([Bind("IdProveedor,Identificacion,NombreProducto,Descripcion,NombreRepresentante,Telefono,Email,Estado")] Proveedor proveedor) { if (ModelState.IsValid) { var validacionDNI = _context.Proveedor.Any(p => p.Identificacion.Equals(proveedor.Identificacion)); var validacionEmail = _context.Proveedor.Any(p => p.Email.Equals(proveedor.Email)); if (validacionDNI || validacionEmail) { if (validacionDNI) { ModelState.AddModelError("Identificacion", "Ya se encuentra registrado"); } if (validacionEmail) { ModelState.AddModelError("Email", "Ya se encuentra registrado"); } return(View("Create")); } _context.Add(proveedor); await _context.SaveChangesAsync(); Thread.Sleep(1000); return(RedirectToAction(nameof(Index))); } return(View(proveedor)); }
public async Task <IActionResult> Create([Bind("IdMonedero,IdCliente,Saldo")] Monedero monedero) { if (ModelState.IsValid) { var validarexist = _context.Monedero.Where(m => m.IdCliente == monedero.IdCliente).FirstOrDefault(); if (validarexist != null) { ModelState.AddModelError("IdCliente", "El cliente ya cuenta con un monedero."); return(View(monedero)); } _context.Add(monedero); await _context.SaveChangesAsync(); Thread.Sleep(2000); return(RedirectToAction(nameof(Index))); } ViewData["IdCliente"] = _context.Cliente .Where(e => e.IdCliente == monedero.IdCliente) .Select(e => new SelectListItem { Text = e.Nombre + " " + e.Apellido1, Value = e.IdCliente.ToString() }); //ViewData["IdCliente"] = new SelectList(_context.Cliente, "IdCliente", "Apellido1", monedero.IdCliente); return(View(monedero)); }
public async Task <IActionResult> Create([Bind("IdEmpleado,Identificacion,Nombre,Apellido1,Apellido2,FechaNac,Telefono,Direccion,Email,Sexo,Area,TipoDeEmp,NumeroSocial,NumeroBancario,Ccss,Profesion,FechaContrato,Estado")] Empleado empleado) { if (ModelState.IsValid) { var validacionDNI = _context.Empleado.Any(e => e.Identificacion.Equals(empleado.Identificacion)); var validacionGmail = _context.Empleado.Any(e => e.Email.Equals(empleado.Email)); if (validacionDNI || validacionGmail) { if (validacionGmail) { ModelState.AddModelError("Email", "Este correo ya esta registrado, intente con otro."); } if (validacionDNI) { ModelState.AddModelError("Identificacion", "Este empleado ya esta registrado"); } return(View("Create")); } _context.Add(empleado); await _context.SaveChangesAsync(); Thread.Sleep(1000); return(RedirectToAction(nameof(Index))); } return(View(empleado)); }
public void RegisterUser(string firstName, string lastName, string username, string email, string password) { using var db = new GymContext(); //var user = db.Users; //string encryptedPassword = Encrypt(password); db.Add(new User { FirstName = firstName, LastName = lastName, UserName = username, Email = email, Password = password }); db.SaveChanges(); }
public async Task <IActionResult> Create([Bind("UserId,Username")] Users users) { if (ModelState.IsValid) { _context.Add(users); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(users)); }
public async Task <IActionResult> Create([Bind("CategoryId,CategoryName")] Categories categories) { if (ModelState.IsValid) { _context.Add(categories); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(categories)); }
public async Task <IActionResult> Create([Bind("Membership_Id,Staff_Id,Member_Id,StartDate,EndDate,Total")] Membership membership) { if (ModelState.IsValid) { _context.Add(membership); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(membership)); }
public async Task <IActionResult> Create([Bind("IdActividad,Nombre,Descripcion,Duracion")] Actividad actividad) { if (ModelState.IsValid) { _context.Add(actividad); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(actividad)); }
public async Task <IActionResult> Create([Bind("Id,ClassName,ClassSize,NumberOfBookings")] Classes classes) { if (ModelState.IsValid) { _context.Add(classes); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(classes)); }
public async Task <IActionResult> Create([Bind("Staff_id,Staff_Name,Staff_Surname,Gender,Email")] Staff staff) { if (ModelState.IsValid) { _context.Add(staff); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(staff)); }
public async Task <IActionResult> Create([Bind("IdCliente,Identificacion,Nombre,Apellido1,Apellido2,FechaNac,Telefono,Direccion,Email,Estado,Sexo,Casillero,IdTarifa")] Cliente cliente) { if (ModelState.IsValid) { _context.Add(cliente); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(cliente)); }
public async Task <IActionResult> Create([Bind("ExerciseID,Exercise_Name,Planned_Set_Number,Planned_Reps,Planned_Weight")] PlannedWorkout plannedWorkout) { if (ModelState.IsValid) { _context.Add(plannedWorkout); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(plannedWorkout)); }
public async Task <IActionResult> Create([Bind("MembershipTypeId,PaymentType,Cost")] MembershipType membershipType) { if (ModelState.IsValid) { _context.Add(membershipType); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(membershipType)); }
public async Task <IActionResult> Create([Bind("Id,Exercise_Name,Exercise_Description")] Exercise exercise) { if (ModelState.IsValid) { _context.Add(exercise); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(exercise)); }
public async Task <IActionResult> Create([Bind("Member_Id,Member_Name,Member_Surname,Phone,Email,JoinedDate")] Member member) { if (ModelState.IsValid) { _context.Add(member); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(member)); }
public async Task <IActionResult> Create([Bind("StaffID,LastName,FirstName,Occupation,OrganizationName,Address,PhoneNumber")] Staff staff) { if (ModelState.IsValid) { _context.Add(staff); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(staff)); }
public async Task <IActionResult> Create([Bind("IdSala,NombreSala,Descripcion,Estado")] Sala sala) { if (ModelState.IsValid) { _context.Add(sala); await _context.SaveChangesAsync(); Thread.Sleep(1000); return(RedirectToAction(nameof(Index))); } return(View(sala)); }
public async Task <IActionResult> Create([Bind("IdHijo,Identificacion,Nombre,Apellido1,Apellido2,FechaDeNac")] Hijo hijo) { if (ModelState.IsValid) { _context.Add(hijo); await _context.SaveChangesAsync(); Thread.Sleep(1000); return(RedirectToAction(nameof(Index))); } return(View(hijo)); }
public async Task <IActionResult> Create([Bind("IdActividad,Nombre,Descripcion,Duracion,Estado")] Actividad actividad) { if (ModelState.IsValid) { _context.Add(actividad); await _context.SaveChangesAsync(); Thread.Sleep(1000); //Espera 1 segundos y redirecciona al index Actividades porque sino no muestra bien la SweetAlert return(RedirectToAction(nameof(Index))); } return(View(actividad)); }
public async Task <IActionResult> Create([Bind("IdCasillero,Descripcion")] Casillero casillero) { if (ModelState.IsValid) { _context.Add(casillero); await _context.SaveChangesAsync(); Thread.Sleep(1000); return(RedirectToAction(nameof(Index))); } return(View(casillero)); }
public async Task <IActionResult> Create([Bind("ExerciseId,ExerciseName,Duration,CategoryId")] Exercise exercise) { if (ModelState.IsValid) { _context.Add(exercise); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CategoryId"] = new SelectList(_context.Categories, "CategoryId", "CategoryId", exercise.CategoryId); return(View(exercise)); }
public async Task <IActionResult> Create([Bind("IdMatricula,IdClaseGuarderia,IdHijo")] MatriculaGuarderia matriculaGuarderia) { matriculaGuarderia.Fecha = DateTime.Now; if (ModelState.IsValid) { var validarCliente = _context.MatriculaGuarderia.Any(m => m.IdHijo.Equals(matriculaGuarderia.IdHijo)); if (validarCliente) { ModelState.AddModelError("IdHijo", "El hijo que quiere ingresar ya esta matriculado"); Thread.Sleep(3500); return(View("create")); } using (var dbContextTransaction = _context.Database.BeginTransaction()) { try { _context.Add(matriculaGuarderia); var restarCupo = from clas in _context.ClaseGuarderia where (clas.IdClaseGuarderia == matriculaGuarderia.IdClaseGuarderia) select clas; foreach (var item in restarCupo) { if (item.Cupo == 0) { ModelState.AddModelError("", errorMessage: "La clase seleccionada ya no quedan cupo disponible!"); return(View("Create")); } item.Cupo = ((int)(item.Cupo - 1)); _context.ClaseGuarderia.Update(item); } await _context.SaveChangesAsync(); dbContextTransaction.Commit(); } catch { dbContextTransaction.Rollback(); } } Thread.Sleep(1000); return(RedirectToAction(nameof(Index))); } TempData["IdClaseGuarderia"] = new SelectList(_context.ClaseGuarderia, "IdClaseGuarderia", "Estado", matriculaGuarderia.IdClaseGuarderia); ViewData["IdHijo"] = _context.Hijo .Where(h => h.IdHijo == matriculaGuarderia.IdHijo) .Select(h => new SelectListItem { Text = h.Nombre + " " + h.Apellido1, Value = h.IdHijo.ToString() }); return(View(matriculaGuarderia)); }
public async Task <IActionResult> Create([Bind("Services_Id,Member_Id,Staff_Id,Name,Description,Price")] Service service) { if (ModelState.IsValid) { _context.Add(service); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["Member_Id"] = new SelectList(_context.Members, "Member_Id", "Email", service.Member_Id); ViewData["Staff_Id"] = new SelectList(_context.Staffs, "Staff_id", "Email", service.Staff_Id); return(View(service)); }
public async Task <IActionResult> Create([Bind("IdUsuario,NombreUsuario,Contraseña,FechaCreacion,Activo,ConfirmarContraseña,IdRole")] Usuarios usuarios) { if (ModelState.IsValid) { _context.Add(usuarios); await _context.SaveChangesAsync(); Thread.Sleep(1000); return(RedirectToAction(nameof(Index))); } ViewData["IdRole"] = new SelectList(_context.Roles, "IdRole", "NombreRole", usuarios.IdRole); return(View(usuarios)); }
public async Task <IActionResult> Create([Bind("IdProducto,Codigo,Nombre,Descripcion,IdProveedor,Existencia,FechaCadu,IdCategoria,PrecioUnidad")] Producto producto) { if (ModelState.IsValid) { _context.Add(producto); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["IdCategoria"] = new SelectList(_context.Categoria, "IdCategoria", "Codigo", producto.IdCategoria); ViewData["IdProveedor"] = new SelectList(_context.Proveedor, "IdProveedor", "Descripcion", producto.IdProveedor); return(View(producto)); }
public void CreateTraining(int userId, string trainingType, string difficulty, string dailyPlan) { using (var db = new GymContext()) { db.Add(new TrainingProgram { UserId = userId, TrainingType = trainingType, Difficulty = difficulty, DailyPlan = dailyPlan }); db.SaveChanges(); } }