Skip to content

Commit e05d877

Browse files
committed
inital code for refactor
1 parent a94d551 commit e05d877

File tree

91 files changed

+1090
-963
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+1090
-963
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using PortfolioApi.Models.Contacts;
4+
using PortfolioApi.Models.Interfaces.Repos;
5+
using PortfolioApi.Repository.EntityFramework.Context;
6+
7+
namespace PortfolioApi.Core.Domains.Contacts
8+
{
9+
/// <summary>
10+
/// Repository Implementation to access Contact Information
11+
/// </summary>
12+
public class ContactsEntityRepository : IRepoCrud<Contact>
13+
{
14+
private readonly PortfolioContext _portfolioContext;
15+
16+
public ContactsEntityRepository(PortfolioContext portfolioContext)
17+
{
18+
_portfolioContext = portfolioContext;
19+
}
20+
21+
public Contact Create(Contact input)
22+
{
23+
var changeTracking = _portfolioContext.Contacts.Add(input);
24+
var result = _portfolioContext.SaveChanges();
25+
return input;
26+
}
27+
28+
public Contact Delete(Contact input)
29+
{
30+
var model = _portfolioContext.Contacts.Find(input.Id);
31+
_portfolioContext.Remove(model);
32+
_portfolioContext.SaveChanges();
33+
return model;
34+
}
35+
36+
public IEnumerable<Contact> Get(Contact input)
37+
{
38+
if (input.ProfileId != default(int))
39+
{
40+
return _portfolioContext.Contacts
41+
.Where(x => x.ProfileId == input.ProfileId);
42+
}
43+
else
44+
{
45+
var result = new List<Contact>();
46+
var item = _portfolioContext.Contacts.Find(input.Id);
47+
if(item != null) result.Add(item);
48+
return result;
49+
}
50+
}
51+
52+
public Contact Update(Contact input)
53+
{
54+
var m = _portfolioContext.Contacts.Find(input.Id);
55+
m.Info = input.Info;
56+
var result = _portfolioContext.SaveChanges();
57+
return m;
58+
}
59+
}
60+
}
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using PortfolioApi.Core.Domains.Contacts.Interfaces;
2+
using PortfolioApi.Models.Contacts;
3+
using PortfolioApi.Models.Helpers;
4+
5+
namespace PortfolioApi.Core.Domains.Contacts
6+
{
7+
/// <summary>
8+
/// Main Contacts Logic
9+
/// </summary>
10+
public class ContactsService : IContactsService
11+
{
12+
public ServiceMessage<Contact> Create(Contact input)
13+
{
14+
throw new System.NotImplementedException();
15+
}
16+
17+
public ServiceMessage<Contact> Delete(Contact input)
18+
{
19+
throw new System.NotImplementedException();
20+
}
21+
22+
public ServiceMessage<Contact> Get(Contact input)
23+
{
24+
throw new System.NotImplementedException();
25+
}
26+
27+
public ServiceMessage<Contact> Update(Contact input)
28+
{
29+
throw new System.NotImplementedException();
30+
}
31+
}
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using PortfolioApi.Models.Contacts;
2+
using PortfolioApi.Models.Helpers;
3+
using PortfolioApi.Models.Interfaces.Validators;
4+
5+
namespace PortfolioApi.Core.Domains.Contacts
6+
{
7+
/// <summary>
8+
/// The validation of Contact Information
9+
/// </summary>
10+
public class ContactsUpdateValidator : IValidatorUpdate<Contact>
11+
{
12+
public Validation<Contact> Validate(Contact input)
13+
{
14+
throw new System.NotImplementedException();
15+
}
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using PortfolioApi.Models.Contacts;
2+
using PortfolioApi.Models.Helpers;
3+
using PortfolioApi.Models.Interfaces;
4+
5+
namespace PortfolioApi.Core.Domains.Contacts.Interfaces
6+
{
7+
public interface IContactsService : ICrud<Contact, ServiceMessage<Contact>>
8+
{
9+
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using PortfolioApi.Models.Experiences;
4+
using PortfolioApi.Models.Interfaces.Repos;
5+
using PortfolioApi.Repository.EntityFramework.Context;
6+
7+
namespace PortfolioApi.Core.Domains.Experiences
8+
{
9+
/// <summary>
10+
/// Repository Implementation to access the Experience Entities
11+
/// </summary>
12+
public class ExperienceEntityRepository : IRepoCrud<Experience>
13+
{
14+
private readonly PortfolioContext _portfolioContext;
15+
16+
public ExperienceEntityRepository(PortfolioContext portfolioContext)
17+
{
18+
_portfolioContext = portfolioContext;
19+
}
20+
21+
public Experience Create(Experience input)
22+
{
23+
var changeTracking = _portfolioContext.Experiences.Add(input);
24+
var result = _portfolioContext.SaveChanges();
25+
return input;
26+
}
27+
28+
public Experience Delete(Experience input)
29+
{
30+
var model = _portfolioContext.Experiences.Find(input.Id);
31+
_portfolioContext.Remove(model);
32+
_portfolioContext.SaveChanges();
33+
return model;
34+
}
35+
36+
public IEnumerable<Experience> Get(Experience input)
37+
{
38+
if (input.Info != null && !string.IsNullOrEmpty(input.Type) && !string.IsNullOrEmpty(input.Info.Title))
39+
{
40+
return _portfolioContext.Experiences.Where(
41+
x => x.Type == input.Type
42+
&& x.Info.Title == input.Info.Title);
43+
}
44+
else if (!string.IsNullOrEmpty(input.Type))
45+
{
46+
return _portfolioContext.Experiences.Where(x => x.Type == input.Type);
47+
}
48+
else
49+
{
50+
var result = new List<Experience>();
51+
var item = _portfolioContext.Experiences.Find(input.Id);
52+
if(item != null) result.Add(item);
53+
return result;
54+
}
55+
}
56+
57+
public Experience Update(Experience input)
58+
{
59+
var m = _portfolioContext.Experiences.Find(input.Id);
60+
m.Info = input.Info;
61+
var result = _portfolioContext.SaveChanges();
62+
return m;
63+
}
64+
}
65+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace PortfolioApi.Core.Domains.Experiences
2+
{
3+
/// <summary>
4+
/// Repository Implementation to access the relationships between Experience Entites
5+
/// </summary>
6+
public class ExperiencesRelationshipRepository
7+
{
8+
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using core.Domains.Experiences.Interfaces;
2+
using PortfolioApi.Models.Experiences;
3+
using PortfolioApi.Models.Helpers;
4+
5+
namespace PortfolioApi.Core.Domains.Experiences
6+
{
7+
/// <summary>
8+
/// Main Experiences Logic
9+
/// </summary>
10+
public class ExperiencesService : IExperiencesService
11+
{
12+
public ServiceMessage<Experience> Create(Experience input)
13+
{
14+
throw new System.NotImplementedException();
15+
}
16+
17+
public ServiceMessage<Experience> Delete(Experience input)
18+
{
19+
throw new System.NotImplementedException();
20+
}
21+
22+
public ServiceMessage<Experience> Get(Experience input)
23+
{
24+
throw new System.NotImplementedException();
25+
}
26+
27+
public ServiceMessage<Experience> Update(Experience input)
28+
{
29+
throw new System.NotImplementedException();
30+
}
31+
}
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using PortfolioApi.Models.Experiences;
2+
using PortfolioApi.Models.Interfaces.Validators;
3+
4+
namespace PortfolioApi.Core.Domains.Experiences
5+
{
6+
/// <summary>
7+
/// The Validation of Experience entities
8+
/// </summary>
9+
public class ExperiencesValidator : IValidatorUpdate<Experience>
10+
{
11+
public Models.Helpers.Validation<Experience> Validate(Experience input)
12+
{
13+
throw new System.NotImplementedException();
14+
}
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using PortfolioApi.Models.Experiences;
2+
using PortfolioApi.Models.Helpers;
3+
using PortfolioApi.Models.Interfaces;
4+
5+
namespace core.Domains.Experiences.Interfaces
6+
{
7+
public interface IExperiencesService : ICrud<Experience, ServiceMessage<Experience>>
8+
{
9+
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System.Collections.Generic;
2+
using PortfolioApi.Models.Helpers;
3+
using PortfolioApi.Models.Interfaces;
4+
using PortfolioApi.Models.Profiles;
5+
6+
namespace core.Domains.Profiles.Interfaces
7+
{
8+
public interface IProfilesService : ICrud<Profile, ServiceMessage<Profile>>
9+
{
10+
IEnumerable<Profile> GetAll();
11+
}
12+
}
+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System.Collections.Generic;
2+
using core.Domains.Profiles.Interfaces;
3+
using PortfolioApi.Models.Helpers;
4+
using PortfolioApi.Models.Interfaces.Repos;
5+
using PortfolioApi.Models.Interfaces.Validators;
6+
using PortfolioApi.Models.Profiles;
7+
8+
namespace PortfolioApi.Core.Domains.Profiles
9+
{
10+
/// <summary>
11+
/// The main profile logic
12+
/// </summary>
13+
public class ProfilesService : IProfilesService
14+
{
15+
private readonly IValidatorCreate<Profile> _validateForCreation;
16+
private readonly IRepoCrud<Profile> _profileRepo;
17+
18+
public ProfilesService(IValidatorCreate<Profile> validateForCreation, IRepoCrud<Profile> profileRepo)
19+
{
20+
_validateForCreation = validateForCreation;
21+
_profileRepo = profileRepo;
22+
}
23+
24+
public ServiceMessage<Profile> Create(Profile input)
25+
{
26+
var validationResult = _validateForCreation.Validate(input);
27+
var result = new ServiceMessage<Profile> { Validation = validationResult };
28+
if (validationResult.IsValid)
29+
{
30+
result.Result = _profileRepo.Create(validationResult.Result);
31+
}
32+
return result;
33+
}
34+
35+
public ServiceMessage<Profile> Delete(Profile input)
36+
{
37+
throw new System.NotImplementedException();
38+
}
39+
40+
public ServiceMessage<Profile> Get(Profile input)
41+
{
42+
throw new System.NotImplementedException();
43+
}
44+
45+
public IEnumerable<Profile> GetAll()
46+
{
47+
throw new System.NotImplementedException();
48+
}
49+
50+
public ServiceMessage<Profile> Update(Profile input)
51+
{
52+
throw new System.NotImplementedException();
53+
}
54+
}
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using PortfolioApi.Models.Interfaces.Repos;
4+
using PortfolioApi.Models.Profiles;
5+
using PortfolioApi.Repository.EntityFramework.Context;
6+
7+
namespace PortfolioApi.Core.Domains.Profiles.Repository
8+
{
9+
/// <summary>
10+
/// The Repository Implementation for Profile Entities
11+
/// </summary>
12+
public class ProfilesEntityRepository : IRepoCrud<Profile>
13+
{
14+
private readonly PortfolioContext _portfolioContext;
15+
16+
public ProfilesEntityRepository(PortfolioContext portfolioContext)
17+
{
18+
_portfolioContext = portfolioContext;
19+
}
20+
21+
public Profile Create(Profile input)
22+
{
23+
var changeTracking = _portfolioContext.Profiles.Add(input);
24+
var result = _portfolioContext.SaveChanges();
25+
return input;
26+
}
27+
28+
public Profile Delete(Profile input)
29+
{
30+
var model = _portfolioContext.Profiles.Find(input.Id);
31+
_portfolioContext.Remove(model);
32+
_portfolioContext.SaveChanges();
33+
return model;
34+
}
35+
36+
public IEnumerable<Profile> Get(Profile input)
37+
{
38+
if (input.Info != null && !string.IsNullOrEmpty(input.Info.LastName) && !string.IsNullOrEmpty(input.Info.FirstName))
39+
{
40+
return _portfolioContext.Profiles.Where(
41+
x => x.Info.LastName == input.Info.LastName
42+
&& x.Info.FirstName == input.Info.FirstName);
43+
}
44+
else if (input.Info != null && !string.IsNullOrEmpty(input.Info.LastName))
45+
{
46+
return _portfolioContext.Profiles.Where(x => x.Info.LastName == input.Info.LastName);
47+
}
48+
else
49+
{
50+
var result = new List<Profile>();
51+
var item = _portfolioContext.Profiles.Find(input.Id);
52+
if(item != null) result.Add(item);
53+
return result;
54+
}
55+
}
56+
57+
public Profile Update(Profile input)
58+
{
59+
var m = _portfolioContext.Profiles.Find(input.Id);
60+
m.Info = input.Info;
61+
var result = _portfolioContext.SaveChanges();
62+
return m;
63+
}
64+
}
65+
}

0 commit comments

Comments
 (0)