public Operation <long> AddUserContributionToGroup(ContributeModel model) { return(Operation.Create(() => { var existInGroup = _repo.Query <UserGroup>().Where(ug => ug.UserId == model.UserId && ug.GroupId == model.GroupId).FirstOrDefault(); if (existInGroup == null) { throw new Exception("This User does not belong to this group"); } var contribution = _repo.Query <Contribute>().Where(c => c.UserId == model.UserId && c.MonthId == model.MonthId && c.GroupId == model.GroupId).FirstOrDefault(); if (contribution != null) { throw new Exception("This User has contributed in this group"); } var yearId = _repo.Query <Year>().Where(y => y.YearName == DateTime.Now.Year.ToString()).Select(y => y.YearId).FirstOrDefault(); var entity = new Contribute() { Amount = 10000, GroupId = model.GroupId, MonthId = model.MonthId, UserId = model.UserId, TransactionDate = DateTime.Now, YearId = yearId }; _repo.Add <Contribute>(entity); _repo.SaveChanges().Unwrap(); return (long)entity.ContributeId; })); }
public Operation <ContributeModel> GetContributionInGroup(int groupId, int userId) { return(Operation.Create(() => { var contribute = _repo.Query <Contribute>().Where(c => c.GroupId == groupId && c.UserId == userId).FirstOrDefault(); if (contribute == null) { throw new Exception("This User is not in this group yet"); } var user = _repo.GetByID <User>(userId); var model = new ContributeModel(contribute); return model; })); }
public IHttpActionResult CreateUserContribution([FromBody] ContributeModel model) { var op = _contributionManager.AddUserContributionToGroup(model); return(this.OperationResult(op)); }