Beispiel #1
0
        //si la tabla de historicos no tiene ningula linea, el estado es pendiente
        public static SolFacState GetCurrentState(AppDbContext context, int idBillingMilestone)
        {
            SolFacHist solFacHist = context.SolFacHists
                                    .Where(h => h.IdBillingMilestone == idBillingMilestone)
                                    .OrderByDescending(o => o.Date)
                                    .Take(1).SingleOrDefault();

            SolFacState currState;

            if (solFacHist == null)
            {
                currState = null;
            }
            else
            {
                currState = solFacHist.SolFacState;
            }

            return(currState);
        }
Beispiel #2
0
        public void SaveOrUpdate2(BillingMilestone o, int idUser, Boolean simple, Boolean update, Boolean rechazar)
        {
            AppDbContext appContext = (AppDbContext)context;
            BillingMilestoneDetailRepository repoDeta;

            //profile
            Profile profile = appContext.Users.Where(u => u.Id == idUser).Include(p => p.Profile).Select(s => s.Profile).FirstOrDefault();

            //historial
            var repoHist = new SolFacHistRepository();

            repoHist.context = base.context;

            SolFacState currState = SolFacStateHelper.GetCurrentState(appContext, o.Id);
            SolFacState prevState = SolFacStateHelper.GetPrevState(appContext, currState);
            SolFacState nextState = SolFacStateHelper.GetNextState(appContext, currState);

            //solo hacer todo si existe el siguiente estado
            //si es siguiente estado es nulo, es porque la acción no está permitida
            if (rechazar == false && nextState != null || rechazar && prevState != null)
            {
                //Encabezado
                //o.Name = o.ProjectName + o.ContractNumber;
                if (update)
                {
                    o.CurrState     = currState.Code;
                    o.IdSolFacState = currState.Id;
                }
                else
                {
                    if (rechazar)
                    {
                        o.CurrState     = prevState.Code;
                        o.IdSolFacState = prevState.Id;
                    }
                    else
                    {
                        o.CurrState     = nextState.Code;
                        o.IdSolFacState = nextState.Id;
                    }
                }
                base.SaveOrUpdate(o);

                base.context.SaveChanges();

                //if (!simple)
                //{
                //historial
                SolFacHist solfacthist = new SolFacHist();
                solfacthist.IdBillingMilestone = o.Id;
                if (update)
                {
                    solfacthist.IdSolFacState = currState.Id;
                }
                else
                {
                    if (rechazar)
                    {
                        solfacthist.IdSolFacState = prevState.Id;
                    }
                    else
                    {
                        solfacthist.IdSolFacState = nextState.Id;
                    }
                }
                solfacthist.Canceled = rechazar;
                solfacthist.IdUser   = idUser;
                solfacthist.Date     = DateTime.Now;
                repoHist.SaveOrUpdate(solfacthist);

                //}

                if (!simple)
                {
                    //detalles
                    repoDeta         = new BillingMilestoneDetailRepository();
                    repoDeta.context = base.context;
                    if (o.BillingMilestoneDetails != null)
                    {
                        foreach (var d in o.BillingMilestoneDetails)
                        {
                            repoDeta.SaveOrUpdate(d);
                        }
                    }
                }

                //guardar cambios
                base.context.SaveChanges();

                if (!simple)
                {
                    //limpiar recursos
                    repoDeta = null;
                }
            }
        }