private ValidationMessageCollection OnUpdateFailedFunc(DbUpdateConcurrencyException dbUpdateEx, UpdateDepartment.CommandModel commandModel, ref byte[] rowVersion)
        {
            var validationMessages = new ValidationMessageCollection();

            var entry = dbUpdateEx.Entries.Single();
            var databaseEntry = entry.GetDatabaseValues();
            if (databaseEntry == null)
            {
                validationMessages.Add(string.Empty, "Unable to save changes. The department was deleted by another user.");
                return validationMessages;
            }

            var databaseValues = (Department)databaseEntry.ToObject();
            rowVersion = databaseValues.RowVersion;

            if (databaseValues.Name != commandModel.Name)
                validationMessages.Add(nameof(commandModel.Name), "Current value: " + databaseValues.Name);

            if (databaseValues.Budget != commandModel.Budget)
                validationMessages.Add(nameof(commandModel.Budget), "Current value: " + string.Format("{0:c}", databaseValues.Budget));

            if (databaseValues.StartDate != commandModel.StartDate)
                validationMessages.Add(nameof(commandModel.StartDate), "Current value: " + string.Format("{0:d}", databaseValues.StartDate));

            if (databaseValues.InstructorID != commandModel.InstructorID)
                validationMessages.Add(nameof(commandModel.InstructorID), "Current value: " + _Repository.GetEntity<Instructor>(p => p.ID == databaseValues.InstructorID.Value).FullName);

            validationMessages.Add(string.Empty, "The record you attempted to edit "
                + "was modified by another user after you got the original value. The "
                + "edit operation was canceled and the current values in the database "
                + "have been displayed. If you still want to edit this record, click "
                + "the Save button again. Otherwise click the Back to List hyperlink.");

            return validationMessages;
        }
        public void GetUnderlyingSqlException_ReturnsInnerSqlException()
        {
            SqlException sqlException = this.CreateSqlException();

            DbUpdateConcurrencyException updateException = new DbUpdateConcurrencyException("Error!", new DbUpdateException("Error!", sqlException));

            Assert.Same(sqlException, EntityUtils.GetUnderlyingSqlException(updateException));
        }
        public void DbUpdateConcurrencyException_exposes_public_string_and_inner_exception_constructor()
        {
            var inner = new Exception();

            var ex = new DbUpdateConcurrencyException("Foo", inner);

            Assert.Equal("Foo", ex.Message);
            Assert.Same(inner, ex.InnerException);
        }
 static string GetMessage(DbUpdateConcurrencyException concurrencyException)
 {
     List<DbEntityEntry> entries = concurrencyException.Entries.ToList();
     string entities = String.Join(", ", entries.ConvertAll(GetEntityName));
     return "A concurrency exception occured in the following entities : " + entities;
 }
 public ConcurrencyException(DbUpdateConcurrencyException concurrencyException)
     : base(GetMessage(concurrencyException), concurrencyException)
 {
 }
 /// <summary>
 /// Initializes a new instance of the ConcurrencyException class.
 /// </summary>
 /// <param name="message">The message that describes the error.</param>
 /// <param name="concurrencyException"></param>
 public ConcurrencyException(string message, DbUpdateConcurrencyException concurrencyException)
     : base(message, concurrencyException)
 {
 }
        public void A_DbUpdateConcurrencyException_is_a_concurrency_exception()
        {
            var exception = new DbUpdateConcurrencyException();

            exception.IsConcurrencyException().Should().BeTrue();
        }
예제 #8
0
        public void DbUpdateConcurrencyException_exposes_public_string_constructor()
        {
            var ex = new DbUpdateConcurrencyException("Foo");

            Assert.Equal("Foo", ex.Message);
        }
예제 #9
0
        public void DbUpdateConcurrencyException_exposes_public_string_constructor()
        {
            var ex = new DbUpdateConcurrencyException("Foo");

            Assert.Equal("Foo", ex.Message);
        }