Ejemplo n.º 1
0
        /// <summary>
        /// Called when the entity is about to be saved.
        /// </summary>
        /// <param name="db">The db context</param>
        /// <param name="state">The current entity state</param>
        public override void OnSave(DataContext db, System.Data.EntityState state)
        {
            var js = new JavaScriptSerializer();

            AttachmentsJson = js.Serialize(Attachments);

            base.OnSave(db, state);
        }
Ejemplo n.º 2
0
        public override void OnSave(DataContext db, System.Data.EntityState state)
        {
            JavaScriptSerializer js = new JavaScriptSerializer();

            InternalBody = js.Serialize(Body);

            base.OnSave(db, state);
        }
        public bool HasPendingChanges()
        {
            System.Data.EntityState state = System.Data.EntityState.Added | System.Data.EntityState.Detached | System.Data.EntityState.Modified;
            foreach (var i in ObjectStateManager.GetObjectStateEntries(state))
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 4
0
        public virtual void Update(T entity)
        {
            if (entity == null)
            {
                throw (new System.ArgumentNullException("entity"));
            }

            // **************************************************
            // Just For Debug!
            // **************************************************
            System.Data.EntityState oEntityState =
                DatabaseContext.Entry(entity).State;
            // **************************************************
            // /Just For Debug!
            // **************************************************

            if (oEntityState == System.Data.EntityState.Detached)
            {
                DbSet.Attach(entity);
            }

            // **************************************************
            // Just For Debug!
            // **************************************************
            oEntityState =
                DatabaseContext.Entry(entity).State;
            // **************************************************
            // /Just For Debug!
            // **************************************************

            DatabaseContext.Entry(entity).State =
                System.Data.EntityState.Modified;

            // **************************************************
            // Just For Debug!
            // **************************************************
            oEntityState =
                DatabaseContext.Entry(entity).State;
            // **************************************************
            // /Just For Debug!
            // **************************************************
        }
Ejemplo n.º 5
0
        public override void OnSave(DataContext db, System.Data.EntityState state)
        {
            if (RegionTemplate == null)
            {
                RegionTemplate = db.RegionTemplates.Where(t => t.Id == RegionTemplateId).Single();
            }

            if (!String.IsNullOrEmpty(RegionTemplate.Type))
            {
                var js = new JavaScriptSerializer();

                if (typeof(HtmlString).IsAssignableFrom(ExtensionManager.ExtensionTypes[RegionTemplate.Type]))
                {
                    InternalBody = ((HtmlString)Body).ToString();
                }
                else
                {
                    InternalBody = js.Serialize(Body);
                }
            }
            base.OnSave(db, state);
        }
Ejemplo n.º 6
0
        private static System.Data.EntityState CaseState(ProblemCase theCase)
        {
            // check if any parts of the case have changed.  do this to ensure we update the case0 record time stamp when children are updated
            System.Data.EntityState theState = theCase.ProbCase.EntityState;

            if (theCase.ProbCase.EntityState != System.Data.EntityState.Unchanged)
            {
                return(theState);
            }
            if (theCase.ProbCase.PROB_DEFINE != null && theCase.ProbCase.PROB_DEFINE.EntityState != System.Data.EntityState.Unchanged)
            {
                theState = theCase.ProbCase.PROB_DEFINE.EntityState;
            }
            if (theCase.ProbCase.PROB_CONTAIN != null && theCase.ProbCase.PROB_CONTAIN.EntityState != System.Data.EntityState.Unchanged)
            {
                theState = theCase.ProbCase.PROB_CONTAIN.EntityState;
            }
            if (theCase.ProbCase.PROB_CAUSE != null && theCase.ProbCase.PROB_CAUSE.EntityState != System.Data.EntityState.Unchanged)
            {
                theState = theCase.ProbCase.PROB_CAUSE.EntityState;
            }
            if (theCase.ProbCase.PROB_CAUSE_ACTION != null && theCase.ProbCase.PROB_CAUSE_ACTION.Count > 0)
            {
                foreach (PROB_CAUSE_ACTION action in theCase.ProbCase.PROB_CAUSE_ACTION)
                {
                    if (action.EntityState != System.Data.EntityState.Unchanged)
                    {
                        return(action.EntityState);
                    }
                }
            }
            if (theCase.ProbCase.PROB_VERIFY != null && theCase.ProbCase.PROB_VERIFY.EntityState != System.Data.EntityState.Unchanged)
            {
                theState = theCase.ProbCase.PROB_VERIFY.EntityState;
            }

            return(theState);
        }
Ejemplo n.º 7
0
        EntityState GetEntityState(System.Data.EntityState entityStates)
        {
            switch (entityStates)
            {
            case System.Data.EntityState.Added:
                return(EntityState.Added);

            case System.Data.EntityState.Deleted:
                return(EntityState.Deleted);

            case System.Data.EntityState.Detached:
                return(EntityState.Detached);

            case System.Data.EntityState.Modified:
                return(EntityState.Modified);

            case System.Data.EntityState.Unchanged:
                return(EntityState.Unchanged);

            default:
                throw new NotImplementedException();
            }
        }
Ejemplo n.º 8
0
 public void ChangeObjectState <T>(T entity, System.Data.EntityState newState)
 {
 }
Ejemplo n.º 9
0
 public void StateManager(T Entity, System.Data.EntityState state)
 {
     this.Context.ObjectStateManager.ChangeObjectState(Entity, state);
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Determines whether the specified database context contains the specified entity. It does this by checking all
        /// the entries inside the change tracker of the database context.
        /// </summary>
        /// <param name="dbContext">The database context.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="entityStates">The entity states.</param>
        /// <returns><c>true</c> if the specified database context contains entity; otherwise, <c>false</c>.</returns>
        /// <exception cref="ArgumentNullException">The <paramref name="dbContext" /> is <c>null</c>.</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="entity" /> is <c>null</c>.</exception>
        public static DbEntityEntry GetEntityEntry(this DbContext dbContext, object entity, EntityState entityStates)
        {
            Argument.IsNotNull("dbContext", dbContext);
            Argument.IsNotNull("entity", entity);

            var entries = dbContext.GetChangeTrackerEntries(entityStates);

            var entityEntry = entries.FirstOrDefault(x => ReferenceEquals(x, entity));

            return(entityEntry);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Gets the change tracker entries of the database context.
        /// </summary>
        /// <param name="dbContext">The database context.</param>
        /// <param name="entityStates">The entity states.</param>
        /// <returns>List&lt;DbEntityEntry&gt;.</returns>
        /// <exception cref="ArgumentNullException">The <paramref name="dbContext" /> is <c>null</c>.</exception>
        public static List <DbEntityEntry> GetChangeTrackerEntries(this DbContext dbContext, EntityState entityStates)
        {
            var states = new List <EntityState>();

            foreach (var value in Enum <EntityState> .GetValues())
            {
                if (Enum <EntityState> .Flags.IsFlagSet(entityStates, value))
                {
                    states.Add(value);
                }
            }

            var entries = (from entry in dbContext.ChangeTracker.Entries()
                           where states.Contains(entry.State)
                           select entry).ToList();

            return(entries);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Determines whether the specified database context contains the specified entity. It does this by checking all
        /// the entries inside the change tracker of the database context.
        /// </summary>
        /// <param name="dbContext">The database context.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="entityStates">The entity states.</param>
        /// <returns><c>true</c> if the specified database context contains entity; otherwise, <c>false</c>.</returns>
        /// <exception cref="ArgumentNullException">The <paramref name="dbContext" /> is <c>null</c>.</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="entity" /> is <c>null</c>.</exception>
        public static bool ContainsEntityEntry(this DbContext dbContext, object entity, EntityState entityStates)
        {
            Argument.IsNotNull("dbContext", dbContext);
            Argument.IsNotNull("entity", entity);

            return(GetEntityEntry(dbContext, entity, entityStates) != null);
        }
Ejemplo n.º 13
0
        public ActionResult ClientEntry(LineModel model, string viewName = null)
        {
            if (System.Configuration.ConfigurationManager.AppSettings["UseHours"] != "1")
            {
                if (model.EditLine.EndTime <= model.EditLine.StartTime)
                {
                    ModelState.AddModelError("EditLine.EndTime", "End Time must be after start time");
                }
            }
            //Check Pieces
            if (ETSData.Helpers.CheckIfPiecesNeeded(ConfigurationManager.ConnectionStrings["ETSConnection"].ConnectionString, model.EditLine.ActivityCode) && model.EditLine.Pieces <= 0)
            {
                ModelState.AddModelError("EditLine.Pieces", "This Activity Code requires Pieces");
            }


            //Check Date
            if (!(model.EditLine.LineDate.Date >= model.WeekStart.Date && model.EditLine.LineDate.Date <= model.WeekStart.Date.AddDays(7)))
            {
                ModelState.AddModelError("EditLine.LineDate", "This Date must be within the week");
            }

            //Check total hours for this client
            double oldHours = ETSData.Helpers.GetHoursThisWeekForClient
                                  (ConfigurationManager.ConnectionStrings["ETSConnection"].ConnectionString,
                                  model.Client.Name_Key, model.EditLine.LineDate);
            double newHours = (model.EditLine.EndTime - model.EditLine.StartTime).TotalHours;

            if (oldHours + newHours > int.Parse(ConfigurationManager.AppSettings["HoursError"]))
            {
                ModelState.AddModelError("EditLine.EndTime", "Total hours can not exceed " + ConfigurationManager.AppSettings["HoursError"] + " hours for the day.");
            }

            if (ModelState.IsValid)
            {
                //Save the edited line
                using (TimeLineDB db = new TimeLineDB())
                {
                    System.Data.EntityState state = System.Data.EntityState.Modified;

                    model.EditLine.UserID = User.Identity.Name;
                    TimeLineModel temp = db.TimeLines.FirstOrDefault(x => x.Id == model.EditLine.Id);

                    if (temp == null)
                    {
                        temp  = new TimeLineModel();
                        state = System.Data.EntityState.Added;
                    }

                    temp.ActivityCode = model.EditLine.ActivityCode;
                    temp.ClientID     = model.Client.Name_Key;
                    temp.LineDate     = model.EditLine.LineDate;
                    temp.Pieces       = model.EditLine.Pieces;
                    temp.StartTime    = model.EditLine.StartTime;
                    temp.EndTime      = model.EditLine.EndTime;

                    if (System.Configuration.ConfigurationManager.AppSettings["UseHours"] == "1")
                    {
                        temp.Hours = model.EditLine.Hours;
                    }
                    else
                    {
                        temp.Hours = (decimal)(model.EditLine.EndTime - model.EditLine.StartTime).TotalHours;
                    }
                    temp.UserID   = model.EditLine.UserID;
                    temp.Comments = model.EditLine.Comments;

                    db.Entry(temp).State = state;
                    db.SaveChanges();
                }
            }

            model = SetupLineModel(model.Client.Name_Key, model.WeekStart.Date);

            GetWeekHourSummary(model, model.Client.Name_Key);
            return(viewName == null?View(model) : View(viewName, model));
        }
Ejemplo n.º 14
0
 public virtual TEntity Save(TEntity entity, System.Data.EntityState state)
 {
     _context.Entry(entity).State = state;
     return(entity);
 }