Example #1
0
        public async Task <IActionResult> Edit(string id)
        {
            try
            {
                if (id.Equals(Guid.Empty))
                {
                    throw new ApplicationException($"No se pudo encontrar el usuario con el id {id}.");
                }

                ApplicationUser user = await _context.Users.FindAsync(id);

                CoachViewModel model = new CoachViewModel()
                {
                    Id     = user.Id,
                    Fields = new CoachFieldsViewModel()
                    {
                        Email           = user.Email,
                        PhoneNumber     = user.PhoneNumber,
                        UserName        = user.UserName,
                        PaternalSurname = user.PaternalSurname,
                        MaternalSurname = user.MaternalSurname,
                        Name            = user.Name
                    }
                };

                return(View(model));
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public async Task <ActionResult> UpdateProfileImageAsync(CoachViewModel viewModel)
        {
            UserProfile item = await HttpContext.GetUserAsync();

            if (item == null)
            {
                return(Json(new { result = false, message = "資料錯誤!!" }));
            }

            String storePath = Path.Combine(FileLogger.Logger.LogDailyPath, Guid.NewGuid().ToString() + ".dat");

            if (Request.Form.Files.Count > 0)
            {
                Request.Form.Files[0].SaveAs(storePath);
            }
            else
            {
                return(Json(new { result = false, message = "請選擇圖像檔!!" }));
            }

            item = item.LoadInstance(models);
            if (item.Attachment == null)
            {
                item.Attachment = new Attachment
                {
                };
            }

            item.Attachment.StoredPath = storePath;
            models.SubmitChanges();

            return(Json(new { result = true, pictureID = item.PictureID }));
        }
Example #3
0
        public ActionResult Create(CoachViewModel cvm, HttpPostedFileBase cimage)
        {
            if (ModelState.IsValid)
            {
                Utilities.CreateUserASP(cvm.Email, cvm.Password, "Coach");
                var coachdb   = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(db));
                var usercoach = coachdb.FindByName(cvm.Email);

                if (cimage != null)
                {
                    var perfil    = System.IO.Path.GetFileName(cimage.FileName);
                    var direccion = "~/Images/Coaches/" + cvm.Email + "_" + perfil;
                    cimage.SaveAs(Server.MapPath(direccion));
                    cvm.Image = cvm.Email + "_" + perfil;
                }

                var coach = new Coach
                {
                    FirstName = cvm.FirstName,
                    LastName  = cvm.LastName,
                    Age       = cvm.Age,
                    Specialty = cvm.Specialty,
                    Image     = cvm.Image,
                    UserId    = usercoach.Id
                };

                db.Coaches.Add(coach);
                db.SaveChanges();
                return(RedirectToAction("AllCoaches"));
            }

            return(View(cvm));
        }
Example #4
0
        private CoachViewModel GetTestCoach()
        {
            var coach = new CoachViewModel {
                Name = "Alex", Lastname = "Olegovich", Surname = "Porada", TeamId = 1
            };

            return(coach);
        }
Example #5
0
        public ActionResult Create()
        {
            var viewModel = new CoachViewModel
            {
                Seats = _dbContext.Seats.ToList()
            };

            return(View(viewModel));
        }
Example #6
0
        public async Task <IActionResult> Add(CoachViewModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(model));
                }

                if (_context.Users.Any(x => x.UserName.Equals(model.Fields.UserName)))
                {
                    return(BadRequest("El usuario especificado ya se encuentra registrado."));
                }

                if (_context.Users.Any(x => x.Email.Equals(model.Fields.Email)))
                {
                    return(BadRequest("El correo electrónico especificado ya se encuentra registrado."));
                }

                var passwordValidator = new PasswordValidator <ApplicationUser>();
                var passwordIsValid   = passwordValidator.ValidateAsync(_userManager, new ApplicationUser(), model.Fields.Password).Result.Succeeded;
                if (!passwordIsValid)
                {
                    return(BadRequest("La contraseña debe contener al menos 1 letra mayúscula, 1 letra minúscula, 1 dígito y un caracter no alfanumérico."));
                }

                var user = new ApplicationUser();
                FillApplicationUser(ref user, model.Fields);
                var identityResult = await _userManager.CreateAsync(user, model.Fields.Password);

                if (!identityResult.Succeeded)
                {
                    return(BadRequest("Ocurrió un problema al registrar."));
                }


                var identityRoleResult = await _userManager.AddToRoleAsync(user, ConstantHelpers.ROLES.COACH);

                //var identityResultRole = await _userManager.AddToRoleAsync(user, new IdentityRole(ConstantHelpers.ROLES.ATHLETE));

                if (!identityRoleResult.Succeeded)
                {
                    return(BadRequest("Ocurrió un problema al registrar."));
                }


                await _context.Users.AddAsync(user);

                return(Ok());
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #7
0
 private CoachRequest Map(CoachViewModel model) => new CoachRequest
 {
     CoachId        = model.CoachId,
     ClubId         = club.Guid,
     DateOfBirth    = model.DateOfBirth,
     Email          = model.Email,
     FirstName      = model.FirstName,
     LastName       = model.LastName,
     Phone          = model.Phone,
     Qualifications = model.Qualifications
 };
        public TreinadorAulaFunc()
        {
            this.InitializeComponent();
            ClassViewModel         = new ClassViewModel();
            CoachViewModel         = new CoachViewModel();
            ClassViewModel.Classes = Class.GetAll();

            var groups = from t in ClassViewModel.Classes
                         group t by t.Coach.Name;

            cvs.Source = groups;
            //ZoomedOutList.ItemsSource = groups;
        }
        public ActionResult GetInformation(PassengerViewModel model)
        {
            CoachViewModel resuftCoach = new CoachViewModel();

            if (model != null && !String.IsNullOrEmpty(model.FirstName))
            {
                PassengerSessionModel.FromSession(this.Session).getPassenger(model);
                TicketDataContext dc      = new TicketDataContext();
                List <Coach>      coaches = new List <Coach>();
                if (model.Hour == null || String.IsNullOrEmpty(model.Hour))
                {
                    coaches = dc.Coaches.Where(q => q.StartDate == DateTime.ParseExact(model.StartDate, "dd/MM/yyyy", null)).ToList();
                }
                else
                {
                    coaches = dc.Coaches.Where(q => q.StartDate == DateTime.ParseExact(model.StartDate, "dd/MM/yyyy", null) && q.StartHour == model.Hour).ToList();
                }

                foreach (Coach coach in coaches)
                {
                    resuftCoach.Name       = coach.Name;
                    resuftCoach.NumberSeat = coach.NumberSeat;
                    resuftCoach.Router     = coach.Router;
                    resuftCoach.StartDate  = coach.StartDate;
                    resuftCoach.StartHour  = coach.StartHour;
                    resuftCoach.Id         = coach.Id;

                    for (int i = 0; i < resuftCoach.NumberSeat; i++)
                    {
                        TicketVewModel ticket = new TicketVewModel();
                        ticket.SeatId = i;
                        resuftCoach.Tickets.Add(ticket);
                    }

                    List <Ticket> tickets = dc.Tickets.Where(q => q.CoachId == resuftCoach.Id).ToList();
                    if (tickets.Count > 0)
                    {
                        foreach (Ticket ticket in tickets)
                        {
                            resuftCoach.Tickets[ticket.SeatId].Status = ticket.Status;
                        }
                    }
                    break;
                }
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
            return(View(resuftCoach));
        }
        public async Task <IActionResult> Create(CoachViewModel coach, IFormFile ava)
        {
            if (!ModelState.IsValid || coach == null)
            {
                ViewBag.Error = CreateError();
                return(View("Error"));
            }
            var coachDto   = _mapper.Map <CoachDTO>(coach);
            var addedCoach = await _сoachService.Create(coachDto, ava, true);

            await UpdateTeam(coach.TeamId, addedCoach.Id);

            return(RedirectToAction("Index"));
        }
Example #11
0
        public async Task <IActionResult> Edit(CoachViewModel model, Guid id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(model));
            }

            var validateUserName = await _context.Users.FirstOrDefaultAsync(x => x.UserName.Equals(model.Fields.UserName) && !x.Id.Equals(model.Id));

            if (validateUserName != null)
            {
                return(BadRequest("El usuario especificado ya se encuentra registrado."));
            }

            var validateEmail = await _context.Users.FirstOrDefaultAsync(x => x.Email.Equals(model.Fields.Email) && !x.Id.Equals(model.Id));

            if (validateEmail != null)
            {
                return(BadRequest("El correo electrónico especificado ya se encuentra registrado."));
            }

            var passwordValidator = new PasswordValidator <ApplicationUser>();
            var passwordIsValid   = passwordValidator.ValidateAsync(_userManager, new ApplicationUser(), model.Fields.Password).Result.Succeeded;

            if (!passwordIsValid)
            {
                return(BadRequest("La contraseña debe contener al menos 1 letra mayúscula, 1 letra minúscula, 1 dígito y un caracter no alfanumérico."));
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(model));
            }

            var user = await _context.Users.FindAsync(model.Id);

            FillApplicationUser(ref user, model.Fields);

            var identityResult = await _userManager.UpdateAsync(user);

            if (!identityResult.Succeeded)
            {
                return(BadRequest("Ocurrió un problema al registrar."));
            }

            user.PasswordHash = _userManager.PasswordHasher.HashPassword(user, model.Fields.Password);
            _context.SaveChanges();
            return(Ok());
        }
Example #12
0
        public async Task <IActionResult> Create([FromBody] CoachViewModel model)
        {
            var user = await GetCurrentUserAsync();

            if (user.Coach != null)
            {
                return(BadRequest("You have coach account already."));
            }

            var coach = model.Adapt <Coach>();

            user.Coach = coach;
            await _coachService.CreateAsync(coach);

            return(Ok(coach.Id));
        }
Example #13
0
        public ActionResult Create(CoachViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Seats = _dbContext.Seats.ToList();
                return(View("Create", viewModel));
            }
            var coach = new Coach
            {
                Name   = viewModel.Name,
                SeatId = viewModel.Seat
            };

            _dbContext.Coaches.Add(coach);
            _dbContext.SaveChanges();
            return(RedirectToAction("Index", "Coachs"));
        }
Example #14
0
        public IActionResult Edit(CoachViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var response = coachService.UpdateCoachProfile(Map(model));

            if (!response.RequestIsFulfilled)
            {
                UpdateModelErrors(response.Errors);
                return(View(model));
            }

            return(ActionResultOnSuccess());
        }
Example #15
0
        public ActionResult Create(CoachViewModel coach)
        {
            if (ModelState.IsValid)
            {
                var role = db.Roles.Where(a => a.Name == Constants.ROLES.COACH).FirstOrDefault();

                if (db.Coaches.Where(a => a.Email.ToLower() == coach.Email.ToLower()).Count() > 0)
                {
                    ViewBag.DuplicateEmail = "This email address is already registered in the system.";
                    return(View(coach));
                }

                if (db.Coaches.Where(a => a.Username.ToLower() == coach.Username.ToLower()).Count() > 0)
                {
                    ViewBag.DuplicateUserName = "******";
                    return(View(coach));
                }

                if (role != null)
                {
                    var coachOb = new Coach();
                    coachOb.FirstName   = coach.FirstName;
                    coachOb.LastName    = coach.LastName;
                    coachOb.ReviewScore = 5;    //5 by default
                    coachOb.Biography   = coach.Biography;
                    coachOb.Skills      = coach.Skills;
                    coachOb.Username    = coach.Username;
                    coachOb.Password    = Security.HashSHA1(coach.Password);
                    coachOb.RoleId      = role.Id;
                    coachOb.Email       = coach.Email;

                    db.Coaches.Add(coachOb);
                    db.SaveChanges();

                    return(RedirectToAction("DashBoard", "Users"));
                }
                else
                {
                    ViewBag.ErrorMsg = "Authentication error!";
                    View("Error");
                }
            }

            return(View());
        }
Example #16
0
        public IActionResult Create(CoachViewModel model, string returnurl)
        {
            ViewData["ReturnUrl"] = returnurl ?? "/administration/coaches";

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var response = coachService.RegisterCoach(Map(model));

            if (!response.RequestIsFulfilled)
            {
                UpdateModelErrors(response.Errors);
                return(View(model));
            }

            return(ActionResultOnSuccess(returnurl));
        }
        public IHttpActionResult Getcoach(int id)
        {
            coach          coach = db.coach.Find(id);
            CoachViewModel Cvm   = new CoachViewModel();

            if (coach == null)
            {
                return(NotFound());
            }
            else
            {
                Cvm.idCoach  = coach.idCoach;
                Cvm.nom      = coach.nom;
                Cvm.prenom   = coach.prenom;
                Cvm.username = coach.username;
                Cvm.password = coach.password;
                Cvm.email    = coach.email;
                Cvm.photo    = coach.photo;
                Cvm.bio      = coach.bio;
                return(Ok(coach));
            }
        }
        public CoachesListViewModel From(List <Coach> coaches)
        {
            var vm          = new CoachesListViewModel();
            var coachesList = new List <CoachViewModel>();

            foreach (var coach in coaches)
            {
                var newCoach = new CoachViewModel()
                {
                    Id        = coach.Id,
                    Name      = ValueFormattingHelper.FormatValue(coach.Name),
                    CoachType = ValueFormattingHelper.FormatValue(coach.CoachType.CoachTypeName),
                    Club      = ValueFormattingHelper.FormatValue(coach.Club.Name)
                };

                coachesList.Add(newCoach);
            }

            vm.Coaches = coachesList;

            return(vm);
        }
        public async Task <IActionResult> AboutUs(CancellationToken cancellationToken)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(coachModel));
                }
                coachModel = await _coachService.GetCoaches(cancellationToken);

                foreach (var item in coachModel.Coaches)
                {
                    item.Extention = string.Format("data:" + item.Extention + ";base64,{0}", Convert.ToBase64String(item.Image));
                }
            }
            catch
            {
                coachModel = null;
            }

            return(View(coachModel));
        }
        // GET: api/coaches
        public List <CoachViewModel> Getcoach()
        {
            //return db.coach;
            List <CoachViewModel> rep = new List <CoachViewModel>();
            var cm = db.coach.ToList();

            foreach (var n in cm)
            {
                CoachViewModel Cvm = new CoachViewModel();
                Cvm.idCoach  = n.idCoach;
                Cvm.nom      = n.nom;
                Cvm.prenom   = n.prenom;
                Cvm.username = n.username;
                Cvm.password = n.password;
                Cvm.email    = n.email;
                Cvm.photo    = n.photo;
                Cvm.bio      = n.bio;

                rep.Add(Cvm);
            }

            return(rep);
        }
Example #21
0
        public ActionResult About(CoachViewModel viewModel)
        {
            var map = AutoMapper.Mapper.Map <Coach>(viewModel);

            return(null);
        }
Example #22
0
 public CoachPage()
 {
     this.InitializeComponent();
     CoachViewModel = new CoachViewModel();
 }
 public CoachContentDialog(CoachViewModel pvm)
 {
     this.InitializeComponent();
     CoachViewModel = pvm;
 }
 public CoachContentDialog()
 {
     this.InitializeComponent();
     CoachViewModel = new CoachViewModel();
 }
Example #25
0
        public IActionResult Add()
        {
            CoachViewModel coachViewModel = new CoachViewModel();

            return(View(coachViewModel));
        }