本文整理汇总了C#中BaseRepository.Create方法的典型用法代码示例。如果您正苦于以下问题:C# BaseRepository.Create方法的具体用法?C# BaseRepository.Create怎么用?C# BaseRepository.Create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BaseRepository
的用法示例。
在下文中一共展示了BaseRepository.Create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddGroupMethod
public GroupMethod AddGroupMethod(long curatorId, long methodicsGroupId, GroupMethod groupMethod)
{
using (var groupMethodRepository = new BaseRepository<GroupMethod>())
{
if (!groupMethodRepository.Context.Clients.Any(x => x.Id == curatorId))
{
throw new UserDoesNotExistException();
}
CuratorMethodicsGroup CMG =
groupMethodRepository.Context.CuratorMethodicsGroups.FirstOrDefault(
x => x.Id == methodicsGroupId && x.Curator.Id == curatorId);
if (CMG == null)
{
throw new MethodicsGroupDoesNotExistException();
}
// Test or Package
if (!String.Equals(groupMethod.MethodsType, Constraints.KMethodsTypeTest) &&
!String.Equals(groupMethod.MethodsType, Constraints.KMethodsTypePackage))
{
throw new RequireFieldException();
}
// Check MethodsId exist in Packages or Tests
if (
(String.Equals(groupMethod.MethodsType, Constraints.KMethodsTypeTest) &&
!groupMethodRepository.Context.Tests.Any(x => x.Id == groupMethod.MethodsId)) ||
(String.Equals(groupMethod.MethodsType, Constraints.KMethodsTypePackage) &&
!groupMethodRepository.Context.Packages.Any(x => x.Id == groupMethod.MethodsId))
)
{
throw new TestPackageDoesNotExistException();
}
groupMethod.CMG = CMG;
if (!groupMethodRepository.Create(groupMethod).Status)
{
throw new CreateException();
}
return groupMethod;
}
}
示例2: AddGroup
public Group AddGroup(Group group)
{
if (String.IsNullOrWhiteSpace(group.Code))
{
throw new RequireFieldException();
}
using (var userRepository = new BaseRepository<OldUser>())
{
var user = userRepository.GetAllItems.FirstOrDefault(x => x.Id == group.Curator);
if (user == null)
{
throw new UserDoesNotExistException();
}
if (user.Role == null)
{
throw new UserRightsException();
}
if (String.Compare(user.Role.Name, Constraints.KCuratorRoleName, StringComparison.CurrentCulture) != 0)
{
throw new UserRightsException();
}
}
using (var groupRepository = new BaseRepository<Group>())
{
if (groupRepository.GetAllItems.Any(x => x.Curator == group.Curator && x.Code == group.Code))
{
throw new GroupUniqueException();
}
group.CreationDate = DateTime.Now;
if (!groupRepository.Create(group).Status)
{
throw new CreateException();
}
}
return group;
}
示例3: SaveResultsForImport
public void SaveResultsForImport(Result result, List<WebConcreteQuestion> webResultItems = null)
{
using (var shellResultRepository = new BaseRepository<ShellResult>())
{
var user = GetUserByResult(result.Id);
var test = GetTestByResult(result.Id);
var resultItems = GetResultItemsByResult(result.Id);
var resultConverterItem = new ResultConverter(user, test, resultItems);
resultConverterItem.SetTestSettingsByDefault();
// Kot test
//if (webResultItems != null && String.Equals(test.CodeName, Constraints.KKotCodeName))
//{
// resultConverterItem.FormKotAnswers(webResultItems);
//}
//else
//{
// resultConverterItem.FormAnswers();
//}
var shellResult = new ShellResult
{
ResultId = result.Id,
TestDate = result.TestDate,
UserId = user.Id,
MethodId = resultConverterItem.TestSettings.MethodId
};
if (webResultItems != null && String.Equals(test.CodeName, Constraints.KKotCodeName))
{
shellResult.Answer = resultConverterItem.FormKotAnswers(webResultItems);
}
else
{
shellResult.Answer = resultConverterItem.FormAnswers();
}
if (!shellResultRepository.Create(shellResult).Status)
{
throw new CreateException();
}
}
}
示例4: SaveResults
/// <summary>
/// Write record to db table Result (person, test, testdate)
/// Write records to db table ResultItems (webResults: array of questionId and answerId)
/// </summary>
/// <param name="personId"></param>
/// <param name="testId"></param>
/// <param name="webResults"></param>
/// <returns></returns>
public Result SaveResults(int personId, int testId, ICollection<WebConcreteQuestion> webResults)
{
var userRepo = new AuthorizationRepository();
if (!userRepo.IsUserExist(personId))
{
throw new UserDoesNotExistException();
}
var testRepo = new TestRepository();
var test = testRepo.GetTestById(testId);
if (test == null)
{
throw new MethodsDoesNotExistException();
}
////TODO : Temporary. Block writing results of test Kot
//if (String.Equals(test.CodeName, Constraints.KKotCodeName))
//{
// return null;
//}
using (var repository = new BaseRepository<Result>())
{
var resultItems = new List<ResultItem>();
//TODO : Hack. If test is Kot we dont save resultItems. In future refactor ResultItems structure
if (!String.Equals(test.CodeName, Constraints.KKotCodeName))
{
foreach (var webConcreteQuestion in webResults)
{
resultItems.AddRange(
webConcreteQuestion.Answers.Select(
answerItem =>
new ResultItem
{
Id = Guid.NewGuid(),
QuestionId = webConcreteQuestion.Id,
AnswerId = Convert.ToInt64(answerItem.Id)
}));
}
}
var resultList = new Result
{
Id = Guid.NewGuid(),
TestId = testId,
UserId = personId,
TestDate = DateTime.Now,
ResultItems = resultItems
};
repository.Create(resultList);
return resultList;
}
}
示例5: AddGroupUser
public GroupUser AddGroupUser(GroupUser groupUser, long groupId, OldUser curator)
{
using (var groupUserRepository = new BaseRepository<GroupUser>())
{
var group = groupUserRepository.Context.Groups.FirstOrDefault(x => x.Id == groupId);
if (group == null)
{
throw new PersonsGroupDoesNotExistException();
}
if (!String.Equals(curator.Role.Name, Constraints.KCuratorRoleName)
|| curator.Id != group.Curator)
{
throw new UserRightsException();
}
if (String.IsNullOrWhiteSpace(groupUser.Email) || String.IsNullOrWhiteSpace(groupUser.FirstName)
|| String.IsNullOrWhiteSpace(groupUser.LastName) || String.IsNullOrWhiteSpace(groupUser.MiddleName))
{
throw new RequireFieldException();
}
//TODO: Refactor, optimization
var code = CodeGenerator.Generate();
while (!CheckCodeUnique(code))
{
code = CodeGenerator.Generate();
}
groupUser.Code = code;
groupUser.Group = group;
if (!groupUserRepository.Create(groupUser).Status)
{
throw new CreateException();
}
return groupUser;
}
}
示例6: RegisterNew
//.........这里部分代码省略.........
// Update password and non required fields; Gender; BirthDate
foundedUser.Password = oldUser.Password;
foundedUser.FirstName = oldUser.FirstName;
foundedUser.LastName = oldUser.LastName;
foundedUser.MiddleName = oldUser.MiddleName;
foundedUser.Gender = oldUser.Gender;
foundedUser.BirthDate = oldUser.BirthDate;
foundedUser.Token = Guid.NewGuid();
foundedUser.ExpirationDate = DateTime.Now.AddMinutes(20);
if (!userRepository.Update(foundedUser).Status)
{
throw new UpdateException();
}
return foundedUser;
}
foundedUser = userRepository.Context.OldUsers.Include("Role").FirstOrDefault(x => String.Equals(x.Login, oldUser.Login));
var emailUser = userRepository.Context.OldUsers.Include("Role").FirstOrDefault(x => String.Equals(x.Email, oldUser.Email));
if (foundedUser != null && emailUser != null)
{
var userWithNewEmail =
userRepository.Context.OldUsers.Include("Role").FirstOrDefault(x => String.Equals(x.Email, oldUser.Email));
if (userWithNewEmail != null)
{
// OldUser with new Email exists
throw new UserEmailException();
}
// Update all non-required credentials and Email, Gender, BirthDate
foundedUser.Email = oldUser.Email;
foundedUser.Password = oldUser.Password;
foundedUser.FirstName = oldUser.FirstName;
foundedUser.LastName = oldUser.LastName;
foundedUser.MiddleName = oldUser.MiddleName;
foundedUser.Gender = oldUser.Gender;
foundedUser.BirthDate = oldUser.BirthDate;
foundedUser.Token = Guid.NewGuid();
foundedUser.ExpirationDate = DateTime.Now.AddMinutes(20);
if (!userRepository.Update(foundedUser).Status)
{
throw new UpdateException();
}
return foundedUser;
}
foundedUser = userRepository.Context.OldUsers.Include("Role").FirstOrDefault(x => String.Equals(x.Email, oldUser.Email));
if (foundedUser != null)
{
var userWithNewLogin =
userRepository.GetAllItems.FirstOrDefault(x => String.Equals(x.Login, oldUser.Login));
if (userWithNewLogin != null)
{
// OldUser with new Login exists
throw new UserLoginException();
}
// Update all non-required credentials and Login, Gender, BirthDate
foundedUser.Login = oldUser.Login;
foundedUser.Password = oldUser.Password;
foundedUser.FirstName = oldUser.FirstName;
foundedUser.LastName = oldUser.LastName;
foundedUser.MiddleName = oldUser.MiddleName;
foundedUser.Gender = oldUser.Gender;
foundedUser.BirthDate = oldUser.BirthDate;
foundedUser.Token = Guid.NewGuid();
foundedUser.ExpirationDate = DateTime.Now.AddMinutes(20);
if (!userRepository.Update(foundedUser).Status)
{
throw new UpdateException();
}
return foundedUser;
}
// Login and Email does not matched, register new OldUser
oldUser.Token = Guid.NewGuid();
oldUser.ExpirationDate = DateTime.Now.AddMinutes(20);
oldUser.Role = userRepository.Context.Roles.FirstOrDefault(x => x.Name == Constraints.KClientRoleName);
if (!userRepository.Create(oldUser).Status)
{
throw new CreateException();
}
return oldUser;
}
}
示例7: Register
public void Register(OldUser oldUser)
{
using (var userRepo = new BaseRepository<OldUser>())
{
if (userRepo.GetAllItems.Any(x => String.Compare(x.Login, oldUser.Login) == 0))
{
throw new UserLoginException();
// TODO : Hack
//return;
}
if (userRepo.GetAllItems.Any(x => String.Compare(x.Email, oldUser.Email) == 0))
{
throw new UserEmailException();
// TODO : Hack
//return;
}
oldUser.Token = Guid.NewGuid();
oldUser.ExpirationDate = DateTime.Now.AddMinutes(20);
oldUser.Role = userRepo.Context.Roles.FirstOrDefault(x => x.Name == Constraints.KClientRoleName);
if (!userRepo.Create(oldUser).Status)
{
throw new CreateException();
}
}
}
示例8: CreateSurveysResult
public SurveysResult CreateSurveysResult(long curatorId, CuratorSurveysContent curatorSurveysContent)
{
using(var surveysResultRepository = new BaseRepository<SurveysResult>())
{
Client curator = surveysResultRepository.Context.Clients.FirstOrDefault(x => x.Id == curatorId);
if(curator == null)
{
throw new UserDoesNotExistException();
}
Person personRelated =
surveysResultRepository.Context.Persons.FirstOrDefault(x => x.Id == curator.PersonId);
if(personRelated == null)
{
throw new PersonDoesNotExistException();
}
String methodsType = Constraints.KMethodsTypeCuratorGroup;
// Add row in SurveysResults
SurveysResult surveysResult = new SurveysResult()
{
MethodsType = methodsType,
Date = DateTime.Now,
Person = personRelated,
Name = curatorSurveysContent.Name,
};
surveysResultRepository.Create(surveysResult);
// Add rows in SurveysPersonsGroups
foreach(var personId in curatorSurveysContent.Persons)
{
Person person = surveysResultRepository.Context.Persons.FirstOrDefault(x => x.Id == personId);
if(person != null)
{
SurveysPersonsGroup surveysPersonsGroup = new SurveysPersonsGroup()
{
Person = person,
SurveysResult = surveysResult,
AccessKey = CodeGenerator.Generate()
};
surveysResultRepository.Context.SurveysPersonsGroups.Add(surveysPersonsGroup);
}
}
surveysResultRepository.Context.SaveChanges();
//Add rows in SurveysMethodicsGroupItems
foreach(var methodic in curatorSurveysContent.Methodics)
{
SurveysMethodicsGroupItem surveysMethodicsGroupItem = new SurveysMethodicsGroupItem()
{
MethodsId = methodic.MethodsId,
MethodsType = methodic.MethodsType,
SurveysResultId = surveysResult.Id
};
surveysResultRepository.Context.SurveysMethodicsGroupItems.Add(surveysMethodicsGroupItem);
}
surveysResultRepository.Context.SaveChanges();
return surveysResult;
}
}
示例9: CreateSurveysResult
public SurveysResult CreateSurveysResult(long personId, SurveysResult surveysResult)
{
using (var surveysResultRepository = new BaseRepository<SurveysResult>())
{
Person person = surveysResultRepository.Context.Persons.FirstOrDefault(x => x.Id == personId);
if (person == null)
{
throw new PersonDoesNotExistException();
}
// TODO : Add methods type check (Test, Package)
if (!TestRepository.CheckTestPackage(surveysResult.MethodsType, surveysResult.MethodsId))
{
throw new TestPackageDoesNotExistException();
}
// Check Parent
if (surveysResult.Parent != null)
{
SurveysResult parentSurveyResult =
surveysResultRepository.GetAllItems.FirstOrDefault(
x => x.Id == surveysResult.Parent.Id);
if (parentSurveyResult == null)
{
throw new SurveysResultDoesNotExistException();
}
surveysResult.Parent = parentSurveyResult;
}
surveysResult.Person = person;
surveysResult.Date = DateTime.Now;
surveysResult.Name = String.Empty;
if (!surveysResultRepository.Create(surveysResult).Status)
{
throw new CreateException();
}
// Create empty data conclusions
ServiceRepository serviceRepository = new ServiceRepository();
List<Service> services = serviceRepository.GetServices(surveysResult.MethodsType,
surveysResult.MethodsId);
ConclusionRepository conclusionRepository = new ConclusionRepository();
List<Conclusion> conclusions = new List<Conclusion>();
foreach (var service in services)
{
conclusions.Add(conclusionRepository.CreateConclusion(service.Id, surveysResult.Id));
}
surveysResult.Conclusions = conclusions;
return surveysResult;
}
}
示例10: CreateSurveyShellResultForTest
public SurveysShellResult CreateSurveyShellResultForTest(long surveysResultId, List<SurveysAnswerContent> surveysAnswerContents)
{
using (var shellResultRepository = new BaseRepository<SurveysShellResult>())
{
SurveysResult surveysResult =
shellResultRepository.Context.SurveysResults.FirstOrDefault(x => x.Id == surveysResultId);
if (surveysResult == null)
{
throw new SurveysResultDoesNotExistException();
}
// Surveys shell result existing
SurveysShellResult foundedSurveyShellResult =
shellResultRepository.GetAllItems.FirstOrDefault(x => x.SurveyResultId == surveysResultId);
// surveysResult.Methods_type == "Test"
if (!String.Equals(surveysResult.MethodsType, Constraints.KMethodsTypeTest))
{
return null;
}
Test test = shellResultRepository.Context.Tests.FirstOrDefault(x => x.Id == surveysResult.MethodsId);
if (test == null)
{
throw new TestPackageDoesNotExistException();
}
Person person =
shellResultRepository.Context.Persons.FirstOrDefault(x => x.Id == surveysResult.Person.Id);
if (person == null)
{
throw new PersonDoesNotExistException();
}
int shellMethodId = ResultConverter.GetConsulMethodId(test.CodeName);
String answerStr = ResultConverter.GenerateAnswerString(test.CodeName, surveysAnswerContents, true);
if (foundedSurveyShellResult == null)
{
// Create row in surveysShellResult
SurveysShellResult surveysShellResult = new SurveysShellResult()
{
MethodsId = surveysResult.MethodsId,
MethodsType = surveysResult.MethodsType,
PersonId = person.Id,
ShellMethodId = shellMethodId,
TestDate = surveysResult.Date,
Answer = answerStr,
SurveyResultId = surveysResult.Id
};
if (!shellResultRepository.Create(surveysShellResult).Status)
{
throw new CreateException();
}
return surveysShellResult;
}
else
{
foundedSurveyShellResult.MethodsId = surveysResult.MethodsId;
foundedSurveyShellResult.MethodsType = surveysResult.MethodsType;
foundedSurveyShellResult.PersonId = person.Id;
foundedSurveyShellResult.ShellMethodId = shellMethodId;
foundedSurveyShellResult.TestDate = surveysResult.Date;
foundedSurveyShellResult.Answer = answerStr;
foundedSurveyShellResult.SurveyResultId = surveysResult.Id;
if (!shellResultRepository.Update(foundedSurveyShellResult).Status)
{
throw new UpdateException();
}
return foundedSurveyShellResult;
}
}
}
示例11: GetOAuthUser
/// <summary>
/// 根据githubUser.id获取userId,若首次访问,则新建OAuthAccount记录和User记录
/// </summary>
/// <param name="githubUser"></param>
/// <returns></returns>
private User GetOAuthUser(GithubUserInfoResult githubUser)
{
using (UnitOfWork)
{
User user = null;
var queryManage = new QueryManage(UnitOfWork);
var commonQuery = new CommonQuery(queryManage);
var userRepo = new UserRepository(UnitOfWork);
var oauthAccountRepo = new BaseRepository<OAuthAccount>(UnitOfWork);
const string query = @"SELECT *
FROM oauthaccount
WHERE OAuthCode = @OAuthCode
AND Source = @Source";
var oauthAccount = queryManage.GetList<OAuthAccount>(query, new { OAuthCode = githubUser.id, Source = OAuthSource.Github })
.FirstOrDefault();
if (oauthAccount == null)
{
user = new User
{
UserName = githubUser.login,
Enable = true,
CreatedTime = DateTime.Now
};
user.Id = userRepo.CreateWithIdentity(user);
oauthAccountRepo.Create(new OAuthAccount
{
OAuthCode = githubUser.id.ToString(CultureInfo.InvariantCulture),
Source = OAuthSource.Github,
UserId = user.Id,
CreatedTime = DateTime.Now
});
}
else
{
user = commonQuery.GetUser(oauthAccount.UserId);
}
return user;
}
}
示例12: SetLusherPairSpecialAnswers
public void SetLusherPairSpecialAnswers(long surveysResultId, List<SurveysAnswerContent> surveysAnswerContents)
{
using (var surveysAnswerRepository = new BaseRepository<SurveysAnswer>())
{
SurveysResult surveysResult =
surveysAnswerRepository.Context.SurveysResults.FirstOrDefault(x => x.Id == surveysResultId);
if (surveysResult == null)
{
throw new SurveysResultDoesNotExistException();
}
// Add surveys answers to existing
foreach (var surveysAnswerContent in surveysAnswerContents)
{
foreach (var answerContent in surveysAnswerContent.Answers)
{
surveysAnswerRepository.Create(new SurveysAnswer()
{
QuestionId = surveysAnswerContent.QuestionId,
Answer = answerContent.Id,
SurveysResult = surveysResult
});
}
}
//Form string part for adding to existing
StringBuilder addingPart = new StringBuilder();
foreach (var surveysAnswerContent in surveysAnswerContents)
{
foreach (var answer in surveysAnswerContent.Answers)
{
addingPart.Append(GetColorById(Convert.ToInt32(answer.Id)).Number);
addingPart.Append(",");
}
addingPart.Remove(addingPart.Length - 1, 1);
}
// Update Shell if exists
SurveysShellResult foundedSurveyShellResult =
surveysAnswerRepository.Context.SurveysShellResults.FirstOrDefault(x => x.SurveyResultId == surveysResultId);
if (foundedSurveyShellResult != null)
{
foundedSurveyShellResult.Answer += addingPart.ToString();
surveysAnswerRepository.Context.Entry(foundedSurveyShellResult).State = EntityState.Modified;
surveysAnswerRepository.Context.SaveChanges();
// Form profile string
String profile = LusherPairMethod.GetColorString(foundedSurveyShellResult.Answer);
// Update Conclusion
// Save profile in Conclusion.Data
Service service =
surveysAnswerRepository.Context.Services.FirstOrDefault(
x =>
x.MethodsId == surveysResult.MethodsId &&
String.Equals(x.MethodsType, surveysResult.MethodsType) &&
String.Equals(x.ConclusionType.Code, Constraints.KConclusionTypeProfile));
if (service != null)
{
Conclusion conclusion =
surveysAnswerRepository.Context.Conclusions.FirstOrDefault(
x => x.SurveysResult.Id == surveysResultId && x.Service.Id == service.Id);
conclusion.Data = profile;
surveysAnswerRepository.Context.Entry(conclusion);
surveysAnswerRepository.Context.SaveChanges();
}
}
}
}
示例13: CreateCuratorPerson
public Person CreateCuratorPerson(long curatorId, Person person)
{
using (var personRepository = new BaseRepository<Person>())
{
Client curator = personRepository.Context.Clients.FirstOrDefault(x => x.Id == curatorId);
if (curator == null)
{
throw new UserDoesNotExistException();
}
if (String.IsNullOrWhiteSpace(person.Email) || String.IsNullOrWhiteSpace(person.FirstName)
|| String.IsNullOrWhiteSpace(person.LastName) || String.IsNullOrWhiteSpace(person.MiddleName)
|| !person.BirthDate.HasValue)
{
throw new RequireFieldException();
}
if (person.PersonsGroup != null)
{
PersonsGroup personsGroup =
personRepository.Context.PersonsGroups.FirstOrDefault(x => x.Id == person.PersonsGroup.Id);
if (person.PersonsGroup.Id != 0 && personsGroup == null)
{
throw new PersonsGroupDoesNotExistException();
}
person.PersonsGroup = personsGroup;
}
// Check unique Email
// select Email from Persons where Curator_Id = curatorId
//if (personRepository.GetAllItems.Any(x => x.Curator.Id == curatorId && x.Email == person.Email))
//{
// throw new PersonEmailException();
//}
person.Curator = curator;
if (!personRepository.Create(person).Status)
{
throw new CreateException();
}
return person;
}
}
示例14: CreateCuratorMethodicsGroup
public CuratorMethodicsGroup CreateCuratorMethodicsGroup(long curatorId, CuratorMethodicsGroup methodicsGroup)
{
using (var methodicsGroupsRepository = new BaseRepository<CuratorMethodicsGroup>())
{
Client curator = methodicsGroupsRepository.Context.Clients.FirstOrDefault(x => x.Id == curatorId);
if (curator == null)
{
throw new UserDoesNotExistException();
}
if (String.IsNullOrWhiteSpace(methodicsGroup.Name))
{
throw new RequireFieldException();
}
if (methodicsGroupsRepository.GetAllItems.Any(x => String.Equals(x.Name, methodicsGroup.Name) && x.Curator.Id == curatorId))
{
throw new MethodicsGroupNameException();
}
methodicsGroup.Curator = curator;
if (!methodicsGroupsRepository.Create(methodicsGroup).Status)
{
throw new CreateException();
}
return methodicsGroup;
}
}
示例15: Register
public RegistrationContent Register(RegistrationContent registratedUser)
{
using (var clientRepository = new BaseRepository<Client>())
{
// Check required fields
if (String.IsNullOrWhiteSpace(registratedUser.Login) || String.IsNullOrWhiteSpace(registratedUser.Email) ||
!registratedUser.BirthDate.HasValue || String.IsNullOrWhiteSpace(registratedUser.Password) ||
!registratedUser.Gender.HasValue)
{
throw new RequireFieldException();
}
// Check password validation
if(registratedUser.Password.Length < 6)
{
throw new UserPasswordException();
}
// Check Login unique
// SELECT Login from Clients
if (clientRepository.GetAllItems.Any(x => String.Equals(x.Login, registratedUser.Login)))
{
throw new UserLoginException();
}
// Check Email unique
// SELECT Email from Persons WHERE Curator_Id == null
if (clientRepository.Context.Persons.Include("Curator").Any(x => String.Equals(x.Email, registratedUser.Email) && x.Curator == null))
{
throw new UserEmailException();
}
// Add row in Persons
Person person = new Person()
{
FirstName = registratedUser.FirstName,
LastName = registratedUser.LastName,
MiddleName = registratedUser.MiddleName,
BirthDate = registratedUser.BirthDate.Value,
Gender = registratedUser.Gender.Value,
Email = registratedUser.Email
};
clientRepository.Context.Persons.Add(person);
clientRepository.Context.SaveChanges();
// Add row in Clients
Client client = new Client()
{
Login = registratedUser.Login,
Password = registratedUser.Password,
PersonId = person.Id,
IsCurator = false,
IsAdmin = false
};
if(!clientRepository.Create(client).Status)
{
throw new CreateException();
}
// Add row in Authorizations
Authorization authorization = new Authorization();
authorization.Token = Guid.NewGuid();
authorization.ClientId = client.Id;
authorization.ExpirationDate = DateTime.Now.AddMinutes(Constraints.KExpirationMinutes);
clientRepository.Context.Authorizations.Add(authorization);
clientRepository.Context.SaveChanges();
registratedUser.Id = client.Id;
registratedUser.IsCurator = client.IsCurator;
registratedUser.IsAdmin = client.IsAdmin;
registratedUser.PersonId = person.Id;
registratedUser.Token = authorization.Token;
registratedUser.ExpirationDate = authorization.ExpirationDate;
return registratedUser;
}
}