Пример #1
0
        public static void Seed(IProfilesRepository profilesRepository)
        {
            var existingProfiles = profilesRepository.GetAllProfiles();

            foreach (var profile in profiles)
            {
                profile.PublicationActivity = new List <PublicationActivity>();
                profile.PublicationActivity.Add(new PublicationActivity {
                    LastFillDate = ProfileProvider.NextLastFillDate
                });

                profile.ProfessionalActivity = new List <ProfessionalActivity>();
                profile.ProfessionalActivity.Add(new ProfessionalActivity {
                    LastFillDate = ProfileProvider.NextLastFillDate
                });

                profile.AdditionalActivity = new List <AdditionalActivity>();
                profile.AdditionalActivity.Add(new AdditionalActivity {
                    LastFillDate = ProfileProvider.NextLastFillDate
                });

                var exists = false;
                foreach (var existingProfile in existingProfiles)
                {
                    if (existingProfile.LastName.Equals(profile.LastName) &&
                        existingProfile.FirstName.Equals(profile.FirstName) &&
                        existingProfile.MiddleName.Equals(profile.MiddleName))
                    {
                        exists = true;
                        break;
                    }
                }

                if (exists)
                {
                    continue;
                }

                profilesRepository.CreateProfile(profile);
            }
        }
Пример #2
0
 public Profile CreateProfile([FromBody] Profile profile)
 {
     try
     {
         return(_profilesRepository.CreateProfile(profile));
     }
     catch (SqlException exception)
     {
         var response = new HttpResponseMessage(HttpStatusCode.NotFound)
         {
             Content = new StringContent(exception.Message)
         };
         throw new HttpResponseException(response);
     }
     catch (Exception exception)
     {
         var response = new HttpResponseMessage(HttpStatusCode.Conflict)
         {
             Content = new StringContent(exception.Message)
         };
         throw new HttpResponseException(response);
     }
 }