Exemplo n.º 1
0
        private bool OperativeSight(Guid billDemandUid, Guid sighterId, Guid initiatorId)
        {
            bool retval = false;

            using (var scope = ReadCommittedSupressedScope)
            {
                using (var context = this.CreateContext())
                {
                    var bd = GetBillDemand(context, billDemandUid);

                    if (bd == null)
                    {
                        return(false);
                    }

                    var sdId = EmployeeService.GetIdentityStructDivisionId(sighterId, bd.BudgetId);

                    if (!sdId.HasValue)
                    {
                        return(false);
                    }

                    var sighters = GetLimitManagerSightersOperative(context, bd);

                    if (sighters.Count(p => p.LimitId == sdId.Value) == 0)
                    {
                        return(false);
                    }

                    List <LimitSighter> currentSighters = GetCurrentSighters(context, billDemandUid, SightingType.BillDemandLimitManagerSighting).ConvertAll <LimitSighter>(p => p);

                    foreach (var limitSighter in sighters.Where(p => p.LimitId == sdId.Value))
                    {
                        var sighter = limitSighter;
                        if (currentSighters.Count(p => p.LimitId == sighter.LimitId) == 0)
                        {
                            var newSighting = new WorkflowSighting
                            {
                                EntityId     = billDemandUid,
                                Id           = Guid.NewGuid(),
                                SighterId    = sighterId,
                                InitiatorId  = initiatorId,
                                SightingType = SightingType.BillDemandLimitManagerSighting.Id,
                                SightingTime = DateTime.Now,
                                ItemId       = sighter.LimitId
                            };
                            context.WorkflowSightings.InsertOnSubmit(newSighting);
                            currentSighters.Add(sighter);
                        }
                    }


                    retval =
                        sighters.TrueForAll(
                            p =>
                            currentSighters.FirstOrDefault(s => s.LimitId == p.LimitId) !=
                            null);
                    context.SubmitChanges();
                }

                scope.Complete();
            }

            return(retval);
        }