Example #1
0
        public void Add(DTO.ExpenseGroup newItem)
        {
            Entities.ExpenseGroup newEntity = _mapper.CreateEntityFromDTO(newItem) as Entities.ExpenseGroup;

            db.ExpenseGroups.Add(newEntity);

            db.SaveChanges();
        }
Example #2
0
 public DTO.ExpenseGroup CreateExpenseGroup(ExpenseGroup expenseGroup)
 {
     return new DTO.ExpenseGroup()
     {
         Description = expenseGroup.Description,
         ExpenseGroupStatusId = expenseGroup.ExpenseGroupStatusId,
         Id = expenseGroup.Id,
         Title = expenseGroup.Title,
         UserId = expenseGroup.UserId,
         Expenses = expenseGroup.Expenses.Select(e => expenseFactory.CreateExpense(e)).ToList()
     };
 }
        public RepositoryActionResult<ExpenseGroup> UpdateExpenseGroup(ExpenseGroup eg)
        {
            try
            {
                // you can only update when an expensegroup already exists for this id
                var existingEG = _ctx.ExpenseGroups.FirstOrDefault(exg => exg.Id == eg.Id);
                if (existingEG == null)
                {
                    return new RepositoryActionResult<ExpenseGroup>(eg, RepositoryActionStatus.NotFound);
                }

                // change the original entity status to detached; otherwise, we get an error on attach
                // as the entity is already in the dbSet
                // set original entity state to detached
                _ctx.Entry(existingEG).State = EntityState.Detached;

                // attach & save
                _ctx.ExpenseGroups.Attach(eg);

                // set the updated entity state to modified, so it gets updated.
                _ctx.Entry(eg).State = EntityState.Modified;

                var result = _ctx.SaveChanges();
                if (result > 0)
                {
                    return new RepositoryActionResult<ExpenseGroup>(eg, RepositoryActionStatus.Updated);
                }
                else
                {
                    return new RepositoryActionResult<ExpenseGroup>(eg, RepositoryActionStatus.NothingModified, null);
                }
            }
            catch (Exception ex)
            {
                return new RepositoryActionResult<ExpenseGroup>(null, RepositoryActionStatus.Error, ex);
            }
        }
 /// <summary>
 /// Return bool if ok, the newly-created ExpenseGroup is still available (including
 /// the id) to the calling class.
 /// </summary>
 /// <param name="eg"></param>
 /// <returns></returns>
 public RepositoryActionResult<ExpenseGroup> InsertExpenseGroup(ExpenseGroup eg)
 {
     try
     {
         _ctx.ExpenseGroups.Add(eg);
         var result = _ctx.SaveChanges();
         if (result > 0)
         {
             return new RepositoryActionResult<ExpenseGroup>(eg, RepositoryActionStatus.Created);
         }
         else
         {
             return new RepositoryActionResult<ExpenseGroup>(eg, RepositoryActionStatus.NothingModified, null);
         }
     }
     catch (Exception ex)
     {
         return new RepositoryActionResult<ExpenseGroup>(null, RepositoryActionStatus.Error, ex);
     }
 }
Example #5
0
 public object CreateDataShapedObject(ExpenseGroup expenseGroup, List<string> lstOfFields)
 {
     return CreateDataShapedObject(CreateExpenseGroup(expenseGroup), lstOfFields);
 }
Example #6
0
 public object CreateDataShapeObject(ExpenseGroup expenseGroup, List<string> lstFields)
 {
     //entity to DTO
     return CreateDataShapeObject(CreateExpenseGroup(expenseGroup), lstFields);
 }
 public object CreateDataShapedObject(ExpenseGroup expenseGroup, List<string> listOfFeilds)
 {
     //pass through from entity to DTO
     return CreateDataShapedObject(CreateExpenseGroup(expenseGroup), listOfFeilds);
 }