Exemplo n.º 1
0
        public string SaveCustomer(Customer customer)
        {
            try
            {
                using (var context = new BAPOCOs())
                {
                    context.ContextOptions.LazyLoadingEnabled = false;
                    //Add the customer graph into the context

                    context.Contacts.Attach(customer);

                    context.ObjectStateManager.ChangeObjectState(customer, StateHelpers.GetEquivalentEntityState(customer.State));

                    foreach (Reservation reservation in customer.Reservations.ToList())
                    {
                        context.ObjectStateManager.ChangeObjectState(reservation, StateHelpers.GetEquivalentEntityState(reservation.State));
                    }
                    context.SaveChanges();
                    return("OK");
                }
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Updates the entiy asynchronous.
        /// </summary>
        /// <param name="tDTo">The t d to.</param>
        /// <returns></returns>
        public async Task <int> UpdateEntiyAsync(EmployeePayHistoryDto tDTo)
        {
            var dbentity = typeAdapter.ConvertDtoToEntities(tDTo);

            dbentity.State = State.Modified;
            context.ChangeObjectState <EmployeePayHistory>(dbentity, StateHelpers.GetEquivalentEntityState(dbentity.State));

            return(await uow.SaveAsync());
        }
Exemplo n.º 3
0
        /// <summary>
        /// Update  the EmployeePayHistoryEntiy.
        /// </summary>
        /// <param name="Entiy">The Entiy.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</return
        public bool UpdateEntiy(EmployeePayHistoryDto t)
        {
            var dbentity = typeAdapter.ConvertDtoToEntities(t);

            dbentity.State = State.Modified;
            context.ChangeObjectState <EmployeePayHistory>(dbentity, StateHelpers.GetEquivalentEntityState(dbentity.State));

            uow.Save();
            return(true);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Updates the with attach entiy asynchronous.
        /// </summary>
        /// <param name="tDTo">The t d to.</param>
        /// <returns></returns>
        public async Task <int> UpdateWithAttachEntiyAsync(EmployeePayHistoryDto tDTo)
        {
            var dbentity = typeAdapter.ConvertDtoToEntities(tDTo);

            if (StateHelpers.GetEquivalentEntityState(dbentity.State) == StateHelpers.GetEquivalentEntityState(State.Detached))
            {
                entiesrepository.Attach(dbentity);
            }

            dbentity.State = State.Modified;
            context.ChangeObjectState <EmployeePayHistory>(dbentity, StateHelpers.GetEquivalentEntityState(dbentity.State));

            return(await uow.SaveAsync());
        }
Exemplo n.º 5
0
        /// <summary>
        /// Update With Attach the EmployeePayHistoryEntiy.
        /// </summary>
        /// <param name="Entiy">The Entiy.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</return
        public bool UpdateWithAttachEntiy(EmployeePayHistoryDto t)
        {
            var dbentity = typeAdapter.ConvertDtoToEntities(t);

            if (StateHelpers.GetEquivalentEntityState(dbentity.State) == StateHelpers.GetEquivalentEntityState(State.Detached))
            {
                entiesrepository.Attach(dbentity);
            }

            dbentity.State = State.Modified;
            context.ChangeObjectState <EmployeePayHistory>(dbentity, StateHelpers.GetEquivalentEntityState(dbentity.State));

            uow.Save();
            return(true);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Updates the employee
        /// </summary>
        /// <param name="employee">
        /// The employee.
        /// </param>
        /// <returns>
        /// The update employee 2.
        /// </returns>
        /// <remarks>
        /// For WCF,because wcf cannot persistent ef4 objectcontext
        /// we also need change entity state then save it. Reference book 'Programming Entity framework 4'
        /// </remarks>
        public bool UpdateEmployeeByAttachEntity(Employee employee)
        {
            IObjectContext     context          = RepositoryHelper.GetDbContext();
            IUnitOfWork        uow              = RepositoryHelper.GetUnitOfWork(context);
            EmployeeRepository employRepository = RepositoryHelper.GetEmployeeRepository(context);

            employRepository.Attach(employee);
            employee.rowguid = System.Guid.NewGuid();
            employee.State   = State.Modified;
            //To avoid this error when update record
            // "The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value. The statement has been terminated."
            // exec sp_executesql N'update [HumanResources].[Employee]
            employee.ModifiedDate = System.DateTime.Now;
            context.ChangeObjectState(employee, StateHelpers.GetEquivalentEntityState(employee.State));
            uow.Save();

            return(true);
        }
 public void ChangeState <T>(ObjectState state, T entity) where T : class
 {
     ObjectStateManager.ChangeObjectState(entity, StateHelpers.GetEquivalentEntityState(state));
 }