public async Task <IHttpActionResult> SaveAthleteUser(AthleteUser athleteUser)
        {
            athleteUser.Athlete = await new AthletesBuilder(_repo).SaveAthleteAync(athleteUser.Athlete, User.Identity.GetUserId());
            athleteUser.User    = await new UsersBuilder(_repo).SaveUserAync(athleteUser.User, User.Identity.GetUserId());

            return(Ok(athleteUser));
        }
        public IHttpActionResult AthleteLogin(LoginModel model)
        {
            User userModel = new User();

            try
            {
                userModel.Username = model.Username;
                userModel.Password = model.Password;
            }
            catch (Exception ex)
            {
                return(BadRequest("Información Incorrecta"));
            }

            var         response     = userModel.VerifyLogin();
            AthleteUser athleteModel = new AthleteUser();


            #region User Info Into Athlete Model
            athleteModel.Username = userModel.Username;
            athleteModel.Password = userModel.Password;
            #endregion

            athleteModel.Email = Utility.GetEmail(userModel.Username);

            Person personModel = new Person(athleteModel.Email);
            #region Person Info into Athlete Model

            athleteModel.Name            = personModel.Name;
            athleteModel.LastName        = personModel.LastName;
            athleteModel.Sex             = Utility.GetSexString(personModel.Sex);
            athleteModel.BirthDate       = personModel.BirthDate;
            athleteModel.CityName        = Utility.GetCityString(personModel.CityID);
            athleteModel.CountryName     = Utility.GetCountryString(personModel.CityID);
            athleteModel.TelephoneNumber = personModel.TelephoneNumber;
            #endregion

            Athlete athleteObj = new Athlete(athleteModel.Username);
            #region Athlete Info into Athlete Model
            athleteModel.Weight    = athleteObj.Weight;
            athleteModel.Height    = athleteObj.Height;
            athleteModel.BikerType = Utility.GetBikerTypeString(athleteObj.BikerType);
            athleteModel.Bike      = athleteObj.Bike;
            #endregion

            if (response.IsComplete())
            {
                return(Ok(athleteModel));
            }
            else
            {
                return(BadRequest(response.Message));
            }
        }
        public IHttpActionResult RegisterAthlete(AthleteUser model)
        {
            User    userModel    = new User();
            Person  personModel  = new Person();
            Athlete athleteModel = new Athlete();

            #region Model to model - Person
            personModel.Email           = model.Email;
            personModel.Name            = model.Name;
            personModel.Sex             = Utility.GetSexID(model.Sex);
            personModel.BirthDate       = model.BirthDate;
            personModel.CityID          = Utility.GetCityID(model.CityName, Utility.GetCountryID(model.CountryName));
            personModel.LastName        = model.LastName;
            personModel.TelephoneNumber = model.TelephoneNumber;
            #endregion

            if (model.Role != "Atleta")
            {
                return(BadRequest("Esta función es para atletas."));
            }

            #region Model to model - User
            userModel.Username = model.Username;
            userModel.Password = model.Password;
            userModel.Email    = model.Email;
            userModel.Role     = Utility.GetRoleID(model.Role);
            #endregion

            #region Model to model - Athlete
            athleteModel.Username  = model.Username;
            athleteModel.Weight    = model.Weight;
            athleteModel.Height    = model.Height;
            athleteModel.BikerType = Utility.GetBikerTypeID(model.BikerType);
            athleteModel.Bike      = model.Bike;
            #endregion

            //Adding values to Databases
            personModel.AddPerson();
            var response = userModel.AddUser();
            athleteModel.AddAthlete();

            if (response.IsComplete())
            {
                return(Ok(response.Body));
            }
            else
            {
                return(BadRequest(response.Message));
            }
        }
        public IHttpActionResult PostPhoto(AthleteUser model)
        {
            Person personModel = new Person();

            personModel.Photo = model.Photo;
            personModel.Email = model.Email;

            var response = personModel.UpdatePhoto(model.Photo);

            if (response.IsComplete())
            {
                return(Ok(response.Body));
            }
            else
            {
                return(BadRequest(response.Message));
            }
        }
        public IHttpActionResult UpdateUser(AthleteUser model)
        {
            User    userModel    = new User();
            Person  personModel  = new Person();
            Athlete athleteModel = new Athlete();

            #region Model to model - Person
            personModel.Email           = model.Email;
            personModel.Name            = model.Name;
            personModel.Sex             = Utility.GetSexID(model.Sex);
            personModel.BirthDate       = model.BirthDate.Date;
            personModel.CityID          = Utility.GetCityID(model.CityName, Utility.GetCountryID(model.CountryName));
            personModel.LastName        = model.LastName;
            personModel.TelephoneNumber = model.TelephoneNumber;
            #endregion

            #region Model to model - User
            userModel.Username = model.Username;
            userModel.Password = model.Password;
            userModel.Email    = model.Email;
            userModel.Role     = Utility.GetRoleID(model.Role);
            #endregion

            #region Model to model - Athlete
            athleteModel.Username  = model.Username;
            athleteModel.Weight    = model.Weight;
            athleteModel.Height    = model.Height;
            athleteModel.BikerType = Utility.GetBikerTypeID(model.BikerType);
            #endregion

            //Updating Values into Database
            personModel.UpdatePerson();
            var response = athleteModel.UpdateAthlete();

            if (response.IsComplete())
            {
                return(Ok(response.Body));
            }
            else
            {
                return(BadRequest(response.Message));
            }
        }
Ejemplo n.º 6
0
        public async Task <string> SaveAthleteUser(string filePath, DateTime fromDate, DateTime?untilDate, string teamId)
        {
            AthleteUser athleteUser = new AthleteUser();

            athleteUser.User = CrossSettings.Current.GetValueOrDefaultJson <User>("User");
            if (!string.IsNullOrEmpty(filePath))
            {
                var azureFileData = await AppMedia.UploadMedia(filePath, "/api/Uploads/UserProfilePhoto");

                if (azureFileData == null)
                {
                    return("There was a problem while uploading the file");
                }
                athleteUser.User.ProfileUrl  = azureFileData.Url;
                athleteUser.User.ProfileBlob = azureFileData.BlobName;
            }

            athleteUser.Athlete          = new Athlete();
            athleteUser.Athlete.StartUtc = fromDate;
            athleteUser.Athlete.EndUtc   = untilDate;
            athleteUser.Athlete.TeamId   = teamId;

            // Save profile and athlete
            try
            {
                var result = await new ServiceApi().SaveAthleteUser(athleteUser);
                CrossSettings.Current.AddOrUpdateJson("User", result.User);
                CrossSettings.Current.AddOrUpdateJson("Athlete", result.Athlete);
            }
            catch (Exception e)
            {
                return(e.Message);
            }

            return(null);
        }
Ejemplo n.º 7
0
 public async Task <AthleteUser> SaveAthleteUser(AthleteUser athleteUser)
 {
     athleteUser.User.ProfileContainer = string.IsNullOrEmpty(athleteUser.User.ProfileUrl) ? null : "userprofiles";
     return(await Post <AthleteUser>("/api/Users/SaveAthleteUser", athleteUser));
 }