public void Remove(PosBudget PosBd)
 {
     if (Context.Entry(PosBd).State == EntityState.Detached)
     {
         context.PositionBudgets.Attach(PosBd);
     }
     context.PositionBudgets.Remove(PosBd);
 }
        private List <Error> SaveGrid1(SubperiodVM grid1, IEnumerable <KeyValuePair <string, ModelState> > state, Position record)
        {
            List <Error> errors = new List <Error>();

            var dbBudget = _hrUnitOfWork.Repository <PosBudget>().Where(a => a.PositionId == record.Id).ToList();

            if (grid1.updated != null)
            {
                foreach (var model in grid1.updated)
                {
                    var positionBudget = dbBudget.FirstOrDefault(a => a.Id == model.Id);
                    if (positionBudget != null)
                    {
                        if (model.Amount != null)
                        {
                            positionBudget.BudgetAmount = model.Amount.Value;
                            _hrUnitOfWork.PositionRepository.Attach(positionBudget);
                            _hrUnitOfWork.PositionRepository.Entry(positionBudget).State = EntityState.Modified;
                        }
                        else
                        {
                            _hrUnitOfWork.PositionRepository.Remove(positionBudget);
                        }
                    }
                    else if ((model.Amount != null))
                    {
                        PosBudget pos = new PosBudget()
                        {
                            BudgetAmount = model.Amount.Value,
                            PositionId   = record.Id,
                            SubPeriodId  = model.SubPeriodId
                        };
                        _hrUnitOfWork.PositionRepository.Add(pos);
                    }
                }
            }


            //try
            //{
            //    _hrUnitOfWork.Save();

            //}
            //catch (Exception ex)
            //{

            //    ErrorMessage mess = new ErrorMessage()
            //    {
            //        message = MsgUtils.Instance.Trls(ex.Message)
            //    };
            //    Error er = new Error();
            //    er.errors.Add(mess);
            //    return errors;
            //}

            return(errors);
        }
 public void Attach(PosBudget Posbudget)
 {
     context.PositionBudgets.Attach(Posbudget);
 }
 public DbEntityEntry <PosBudget> Entry(PosBudget PositionBud)
 {
     return(Context.Entry(PositionBud));
 }
 public void Add(PosBudget Posbudget)
 {
     context.PositionBudgets.Add(Posbudget);
 }