public async Task <ActionResult> DeleteRecurring(int weeklyId) { string userId = HttpContext.User.Identity.GetUserId(); int athleteId = db.Athletes.AsNoTracking().Select(a => new { Id = a.Id, AppId = a.ApplicationUserId }).Single(b => b.AppId.Equals(userId)).Id; WeeklyClassSetup weeklyClassSetup = await db.WeeklyClasses.FindAsync(weeklyId); ClassReminders reminders = await db.ClassReminders.FindAsync(athleteId); List <Class> classes = db.Classes.Where(a => a.WeeklyClass.Id.Equals(weeklyId)).ToList(); reminders.Reminders.RemoveAll(c => classes.Contains(c)); foreach (var cls in classes) { cls.AttachedReminders.Remove(reminders); } reminders.WeeklyClassSetups.Remove(weeklyClassSetup); weeklyClassSetup.AttachedReminders.Remove(reminders); await db.SaveChangesAsync(); return(RedirectToAction("Class", new { controller = "Reminders" })); }
public async Task <ActionResult> Signup(string userId, string classId) { if (userId == null || classId == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } int ClassId = Convert.ToInt32(classId); Athlete athlete = await db.Athletes.SingleAsync(a => a.ApplicationUserId.Equals(userId)); Class cls = await db.Classes.SingleAsync(c => c.Id.Equals(ClassId)); if (!cls.Attendance.Contains(athlete)) { ViewData["SuccessHeader"] = String.Format("Success"); ViewData["SuccessBody"] = String.Format("You were added to {0}.", cls.Type); cls.Attendance.Add(athlete); athlete.Classes.Add(cls); await db.SaveChangesAsync(); } else { ViewData["SuccessHeader"] = String.Format("We've got you"); ViewData["SuccessBody"] = String.Format("You've already been added to {0}.", cls.Type); } ClassSignupViewModel model = new ClassSignupViewModel { Athlete = athlete, Class = cls }; return(View("Details", model)); }
public async Task <ApiResult <bool> > DeleteAsync([FromRoute] string id) { ApiResult <bool> result = new ApiResult <bool>(); try { using (TransactionScope transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { var user = await _context.Users.FindAsync(id); _context.Remove(user); int i = await _context.SaveChangesAsync(); result.Value = await Task.FromResult(i == 1?true : false); transaction.Complete(); result.Status = ApiResultStatus.SUCCESS; } } catch (Exception ex) { result.Status = ApiResultStatus.FAIL; } return(await Task.FromResult(result)); }
public async Task <IActionResult> PutCliente([FromRoute] int id, [FromBody] Cliente cliente) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != cliente.IdCliente) { return(BadRequest()); } _context.Entry(cliente).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ClienteExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Create(MemberViewModel member)//[Bind("Id,FirstName,LastName,DateOfBirth,PaymentType")] { if (ModelState.IsValid) { var membershipTypeId = 1; if (_context.MembershipTypes.Any(x => x.MembershipTypeId.ToString() == member.PaymentType)) { membershipTypeId = _context.MembershipTypes.First(x => x.MembershipTypeId.ToString() == member.PaymentType).MembershipTypeId; } var memberEntity = new Member { DateOfBirth = member.DateOfBirth, FirstName = member.FirstName, Id = member.MemberID, LastName = member.LastName, TelephoneNumber = member.TelephoneNumber, MembershipTypeId = membershipTypeId }; _context.Members.Add(memberEntity); await _context.SaveChangesAsync(); TempData["Message"] = "Member has been created!"; return(RedirectToAction(nameof(Index))); } return(View(member)); }
public async Task <IHttpActionResult> PutDay(int id, Day day) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != day.DayId) { return(BadRequest()); } db.Entry(day).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DayExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
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 <ActionResult> Create([Bind(Include = "Id,Date,Time,Duration,Type,MaxAttendance")] SingleClassSetup singleClassSetup) { Class c = new Class(); c.MaxAttendance = singleClassSetup.MaxAttendance; c.Type = singleClassSetup.Type; c.Duration = singleClassSetup.Duration; c.Time = ((DateTime)singleClassSetup.Date).Add(singleClassSetup.Time); c.Attendance = new List <Athlete>(); singleClassSetup.GeneratedClass = c; ModelState.Remove("GeneratedClass"); if (ModelState.IsValid) { db.SingleClasses.Add(singleClassSetup); try { await db.SaveChangesAsync(); } catch (DbEntityValidationException e) { e.ThrowDetailedEntityValidationErrors(); } return(RedirectToAction("Index")); } return(View(singleClassSetup)); }
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 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("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("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("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("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("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("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("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("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("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,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("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("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("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("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 <IHttpActionResult> PostProfile(Profile profile) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Profiles.Add(profile); await db.SaveChangesAsync(); return(CreatedAtRoute("DefaultApi", new { id = profile.Id }, profile)); }
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("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(Include = "Name,ThreeMonthPrice,SixMonthPrice,TwelveMonthPrice,Description")] Subscription subscription) { if (ModelState.IsValid) { _db.Subscriptions.Add(subscription); await _db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(subscription)); }
public async Task <ActionResult> Create([Bind(Include = "Id,Time,Duration,Type,MaxAttendance,StartDate,EndDate,SelectedDays")] WeeklyClassSetup weeklyClass) { List <DayOfWeek> chosenDays = weeklyClass.SelectedDays.Select(x => (DayOfWeek)Enum.Parse(typeof(DayOfWeek), x)).ToList(); List <DayOfWeekModel> days = db.DaysOfWeek.Where(d => chosenDays.Contains(d.Day)).ToList(); weeklyClass.Days = days; foreach (var day in days) { day.WeeklyClassSetups.Add(weeklyClass); } // Create Classes WeeklySchedule weeklySchedule = new WeeklySchedule { TimeOfDay = weeklyClass.Time, SchedulingRange = new Period(weeklyClass.StartDate, weeklyClass.EndDate) }; weeklySchedule.SetDays(chosenDays); var schedules = new List <Schedule>() { weeklySchedule }; List <Class> classes = _calendarGenerator.GenerateCalendar(Utilities.Constants.calendarPeriod, schedules).ToList(); foreach (var item in classes) { item.Duration = weeklyClass.Duration; item.MaxAttendance = weeklyClass.MaxAttendance; item.Type = weeklyClass.Type; item.WeeklyClass = weeklyClass; item.Attendance = new List <Athlete>(); } weeklyClass.GeneratedClasses = classes; ModelState.Remove("Days"); ModelState.Remove("GeneratedClasses"); if (ModelState.IsValid) { db.WeeklyClasses.Add(weeklyClass); db.Classes.AddRange(classes); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } else { var errors = ModelState.Select(x => x.Value.Errors).Where(y => y.Count > 0).ToList(); } return(View(weeklyClass)); }