/// <summary> /// Creates new plan in databse /// </summary> /// <param name="plan">Object to be saved to database</param> public Guid CreatePlan(Plan plan) { var planModel = ExpenseManagerMapper.Map <PlanModel>(plan); using (var unitOfWork = UnitOfWorkProvider.Create()) { if (plan.AccountId != null) { var account = _accountRepository.GetById(plan.AccountId.Value); var type = _costTypeRepository.GetById(plan.PlannedTypeId); if (account == null || type == null) { throw new InvalidOperationException("Account of type doesn't exists"); } if (type.AccountId != account.Id) { throw new InvalidOperationException("Cost type doesn't belong to given account"); } planModel.Account = account; planModel.PlannedType = type; } Repository.Insert(planModel); unitOfWork.Commit(); } return(planModel.Id); }
/// <summary> /// Creates new cost info object in databse /// </summary> /// <param name="costInfo"></param> public Guid CreateCostInfo(CostInfo costInfo) { var costInfoModel = ExpenseManagerMapper.Map <CostInfoModel>(costInfo); using (var unitOfWork = UnitOfWorkProvider.Create()) { var account = _accountRepository.GetById(costInfo.AccountId); var type = _costTypeRepository.GetById(costInfo.TypeId); if (account == null || type == null) { throw new InvalidOperationException("Account of type doesn't exists"); } if (type.AccountId != account.Id) { throw new InvalidOperationException("Cost type doesn't belong to given account"); } costInfoModel.Account = account; costInfoModel.Type = type; Repository.Insert(costInfoModel); unitOfWork.Commit(); } return(costInfoModel.Id); }
/// <summary> /// Lists all not achieved badges for given accountId /// </summary> /// <param name="accountId"></param> /// <returns></returns> public List <Badge> ListNotAchievedBadges(Guid accountId) { using (UnitOfWorkProvider.Create()) { _notAchievedBadgesQuery.AccountId = accountId; return(ExpenseManagerMapper.Map <List <Badge> >(_notAchievedBadgesQuery.Execute())); } }
/// <summary> /// Gets currently signed user according to its email /// </summary> /// <param name="email">User unique email</param> /// <param name="includes">Property to include with obtained user</param> /// <returns>User with user details</returns> public User GetCurrentlySignedUser(string email, params Expression <Func <User, object> >[] includes) { using (UnitOfWorkProvider.Create()) { var entity = _userRepository.GetUserByEmail(email, IncludesHelper.ProcessIncludesList <User, UserModel>(includes)); return(ExpenseManagerMapper.Map <UserModel, User>(entity)); } }
/// <summary> /// Gets currently signed user according to its email /// </summary> /// <param name="email">User unique email</param> /// <param name="includeAllProperties">Decides whether all properties should be included</param> /// <returns>User with user details</returns> public User GetCurrentlySignedUser(string email, bool includeAllProperties = true) { using (UnitOfWorkProvider.Create()) { var entity = includeAllProperties ? _userRepository.GetUserByEmail(email, nameof(UserModel.Account)) : _userRepository.GetUserByEmail(email); return(ExpenseManagerMapper.Map <UserModel, User>(entity)); } }
/// <summary> /// Registers user according to provided information /// </summary> /// <param name="userRegistration">User registration information</param> public void RegisterNewUser(User userRegistration) { var userEntity = ExpenseManagerMapper.Map <UserModel>(userRegistration); using (var unitOfWork = UnitOfWorkProvider.Create()) { Repository.Insert(userEntity); unitOfWork.Commit(); } userRegistration.Id = userEntity.Id; }
/// <summary> /// Updates existing cost type /// </summary> /// <param name="costType">Modified existing cost type</param> public void UpdateCostType(CostType costType) { using (var unitOfWork = UnitOfWorkProvider.Create()) { var account = _accountRepository.GetById(costType.AccountId); if (account == null) { throw new InvalidOperationException("Account with given id doesn't exist"); } var costTypeModel = ExpenseManagerMapper.Map <CostTypeModel>(costType); costTypeModel.Account = account; Repository.Update(costTypeModel); unitOfWork.Commit(); } }
/// <summary> /// Gets the list of the s using the Query object. /// </summary> internal virtual IList <T> GetList() { return(ExpenseManagerMapper.Map <IList <TEntity>, IList <T> >(Query.Execute())); }