예제 #1
0
        public void CopyChangedValues_ThrowsArgumentNull_original()
        {
            // Arrange & Act
            Delta <Base> delta = new Delta <Base>();

            ExceptionAssert.ThrowsArgumentNull(() => delta.CopyChangedValues(null), "original");
        }
예제 #2
0
        ColmagCasas IColmagCasasManager.Update(int keyColmagCasaId, Delta <ColmagCasas> changes)
        {
            var methodName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            ColmagCasas result = null;

            try
            {
                logger.Log(LogLevel.Debug, $"Iniciando operación: {methodName}");
                result = context.ColmagCasas.Where((x) => x.ColmagCasaId == keyColmagCasaId).FirstOrDefault();

                if (result == null)
                {
                    logger.Log(LogLevel.Error, $"Llave no Existe: ColmagCasas({keyColmagCasaId})");
                    return(null);
                }
                else
                {
                    changes.CopyChangedValues(result);

                    context.Entry(result).Property("Usuario").CurrentValue          = userId;
                    context.Entry(result).Property("Fecha_Computador").CurrentValue = DateTime.Now;
                }
            }
            catch (Exception ex)
            {
                logger.Log(LogLevel.Error, $"Error en: {methodName}\n{ex.Message}\n{ex.StackTrace}");
            }
            finally
            {
                logger.Log(LogLevel.Debug, $"Finalizada operación: {methodName}");
            }
            return(result);
        }
예제 #3
0
        /// <summary>
        /// Use the PATCH http Verb
        /// Set Content-Type:Application/Json
        /// Call this using following in request body: { "Rating":"ThreeStar" }
        /// </summary>
        /// <param name="key"></param>
        /// <param name="moviePatch"></param>
        /// <returns></returns>
        public IHttpActionResult Patch(int key, Delta <Movie> moviePatch)
        {
            Movie movie = m_service.Find(key);

            if (movie == null)
            {
                return(NotFound());
            }
            moviePatch.CopyChangedValues(movie);
            return(Ok <Movie>(m_service.Save(movie)));
        }
예제 #4
0
        public static TEntity Patch <TEntity, TKey>(TKey key, Delta <TEntity> delta, UnitOfWork uow) where TEntity : class
        {
            TEntity existing = uow.GetObjectByKey <TEntity>(key);

            if (existing != null)
            {
                delta.CopyChangedValues(existing);
                uow.CommitChanges();
            }
            return(existing);
        }
예제 #5
0
파일: DeltaTest.cs 프로젝트: gcoman/WebApi
        public void CopyChangedValues_UnRelatedType_Throws_Argument()
        {
            // Arrange
            Delta <Base>   delta           = new Delta <Base>(typeof(Derived));
            AnotherDerived unrelatedEntity = new AnotherDerived();

            // Act & Assert
            ExceptionAssert.ThrowsArgument(
                () => delta.CopyChangedValues(unrelatedEntity),
                "original",
                "Cannot use Delta of type 'Microsoft.AspNet.OData.Test.DeltaTest+Derived' on an entity of type 'Microsoft.AspNet.OData.Test.DeltaTest+AnotherDerived'.");
        }
 public static TEntity Patch <TEntity, TKey>(TKey key, Delta <TEntity> delta) where TEntity : class
 {
     using (UnitOfWork uow = ConnectionHelper.CreateSession()) {
         TEntity existing = uow.GetObjectByKey <TEntity>(key);
         if (existing != null)
         {
             delta.CopyChangedValues(existing);
             uow.CommitChanges();
         }
         return(existing);
     }
 }
 public static TEntity Patch <TEntity, TKey>(TKey key, Delta <TEntity> delta, BaseController baseController) where TEntity : class
 {
     using (UnitOfWork uow = baseController.GetNewUow())
     {
         TEntity existing = uow.GetObjectByKey <TEntity>(key);
         if (existing != null)
         {
             delta.CopyChangedValues(existing);
             uow.CommitChanges();
         }
         return(existing);
     }
 }
        public IHttpActionResult Patch(RgFisicaJuridica _RgFisicaJuridica)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Delta <RgFisicaJuridica> _Delta = new Delta <RgFisicaJuridica>();

            _Delta.CopyChangedValues(_RgFisicaJuridica);

            _Delta.Patch(_RgFisicaJuridica);
            return(Updated(_RgFisicaJuridica));
        }
        public IHttpActionResult Patch(GeTmpValor _GeTmpValor)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Delta <GeTmpValor> _Delta = new Delta <GeTmpValor>();

            _Delta.CopyChangedValues(_GeTmpValor);

            _Delta.Patch(_GeTmpValor);
            return(Updated(_GeTmpValor));
        }
예제 #10
0
        public IHttpActionResult Patch(RgTelefone _RgTelefone)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Delta <RgTelefone> _Delta = new Delta <RgTelefone>();

            _Delta.CopyChangedValues(_RgTelefone);

            _Delta.Patch(_RgTelefone);
            return(Updated(_RgTelefone));
        }
        public IHttpActionResult Patch(GeEmpresaConsol _GeEmpresaConsol)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Delta <GeEmpresaConsol> _Delta = new Delta <GeEmpresaConsol>();

            _Delta.CopyChangedValues(_GeEmpresaConsol);

            _Delta.Patch(_GeEmpresaConsol);
            return(Updated(_GeEmpresaConsol));
        }
예제 #12
0
        public IHttpActionResult Patch(RgMunicipio _RgMunicipio)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Delta <RgMunicipio> _Delta = new Delta <RgMunicipio>();

            _Delta.CopyChangedValues(_RgMunicipio);

            _Delta.Patch(_RgMunicipio);
            return(Updated(_RgMunicipio));
        }
예제 #13
0
        public IHttpActionResult Patch(FiNroBanco _FiNroBanco)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Delta <FiNroBanco> _Delta = new Delta <FiNroBanco>();

            _Delta.CopyChangedValues(_FiNroBanco);

            _Delta.Patch(_FiNroBanco);
            return(Updated(_FiNroBanco));
        }
예제 #14
0
        public IHttpActionResult Patch(CtPlanoContabil _CtPlanoContabil)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Delta <CtPlanoContabil> _Delta = new Delta <CtPlanoContabil>();

            _Delta.CopyChangedValues(_CtPlanoContabil);

            _Delta.Patch(_CtPlanoContabil);
            return(Updated(_CtPlanoContabil));
        }
        public IHttpActionResult Patch(GeParametro _GeParametro)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Delta <GeParametro> _Delta = new Delta <GeParametro>();

            _Delta.CopyChangedValues(_GeParametro);

            _Delta.Patch(_GeParametro);
            return(Updated(_GeParametro));
        }
예제 #16
0
        public IHttpActionResult Patch(CtNivelSeis _CtNivelSeis)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Delta <CtNivelSeis> _Delta = new Delta <CtNivelSeis>();

            _Delta.CopyChangedValues(_CtNivelSeis);

            _Delta.Patch(_CtNivelSeis);
            return(Updated(_CtNivelSeis));
        }
예제 #17
0
        public IHttpActionResult Patch(RgRegGeral _RgRegGeral)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Delta <RgRegGeral> _Delta = new Delta <RgRegGeral>();

            _Delta.CopyChangedValues(_RgRegGeral);

            _Delta.Patch(_RgRegGeral);
            return(Updated(_RgRegGeral));
        }
예제 #18
0
        protected internal override TEntity PatchEntity(TKey key, Delta <TEntity> patch)
        {
            TEntity entity = DbSet.Find(key);

            if (entity == null)
            {
                string error = string.Format("Entity lookup failed for key {0} in {1}", key, DbSet);
                throw new ArgumentException(error, "key");
            }

            // Apply changes
            patch.CopyChangedValues(entity);

            this.OnChangeSetSuccess(SaveChanges);
            return(entity);
        }
예제 #19
0
        public async Task <UserDto> UpdatePatch(int id, Delta <User> userPatch)
        {
            var user = await _repository.GetAsync <User>(id);

            if (user == null)
            {
                var model = new UserDto {
                    ErrorMessage = "The user does not exist."
                };
                return(model);
            }
            userPatch.CopyChangedValues(user);
            var result = await _repository.SaveAndReturnEntityAsync(user);

            return(_mapper.Map <UserDto>(result));
        }
예제 #20
0
        public IHttpActionResult Patch([FromODataUri]int key, Delta<Supplier> changedSupplier)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var originalSupplier = _suppliers.SingleOrDefault(p => p.Id == key);
            if (originalSupplier == null)
            {
                return NotFound();
            }

            changedSupplier.CopyChangedValues(originalSupplier);
            return Ok();
        }
예제 #21
0
        public async Task <PersonDto> UpdatePatch(int id, Delta <Person> personPatch)
        {
            var person = await _repository.GetAsync <Person>(id);

            if (person == null)
            {
                var model = new PersonDto {
                    ErrorMessage = "The person does not exist."
                };
                return(model);
            }
            personPatch.CopyChangedValues(person);
            var result = await _repository.SaveAndReturnEntityAsync(person);

            return(_mapper.Map <PersonDto>(result));
        }
예제 #22
0
        public IHttpActionResult Patch([FromODataUri] int key, Delta <Product> changedProduct)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var originalProduct = _products.SingleOrDefault(p => p.Id == key);

            if (originalProduct == null)
            {
                return(NotFound());
            }

            changedProduct.CopyChangedValues(originalProduct);
            return(StatusCode(HttpStatusCode.OK));
        }
예제 #23
0
        public async Task <IActionResult> Patch([FromODataUri] Guid key, [FromBody] Delta <Apartment> requestApartment)
        {
            try
            {
                var existingApartment = await this._apartmentService.GetApartmentByIdAsync(key);

                if (existingApartment == null)
                {
                    return(this.BadRequest("Квартира не найдена."));
                }

                requestApartment.CopyChangedValues(existingApartment);
                existingApartment = await this._apartmentService.UpdateApartmentAsync(key, existingApartment);

                return(this.Updated(existingApartment));
            }
            catch (Exception)
            {
                return(this.BadRequest("Произошла непредвиденная ошибка. Пожалуйста обратитесь к администратору."));
            }
        }