Esempio n. 1
0
        public ResponseModel <bool?> Delete(int id)
        {
            try
            {
                var entity = Repository.GetAll().FirstOrDefault(x => x.Id == id);

                if (entity != null)
                {
                    var delete = Repository.Delete(id);
                    return(ResponseModel <bool?> .GetResponse(delete));
                }
                else
                {
                    return(ResponseModel <bool?> .GetReponseErrors("Id não encontrado para exclusão"));
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Esempio n. 2
0
        public ResponseModel <bool?> Update(TRequest request)
        {
            try
            {
                var entity         = Mapper.Map <TEntity>(request);
                var entityValidate = Validate.Validate(entity);

                if (entityValidate.IsValid)
                {
                    var updated = Repository.Update(entity);
                    return(ResponseModel <bool?> .GetResponse(updated));
                }
                else
                {
                    return(ResponseModel <bool?> .GetReponseErrors(entityValidate.Errors));
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Esempio n. 3
0
        public ResponseModel <bool?> Add(TRequest request)
        {
            try
            {
                var entity         = Mapper.Map <TEntity>(request);
                var entityValidate = Validate.Validate(entity);

                if (entityValidate.IsValid)
                {
                    var objResponse = Mapper.Map <TResponse>(Repository.Add(entity));
                    var added       = objResponse.Id > 0;
                    return(ResponseModel <bool?> .GetResponse(added));
                }
                else
                {
                    return(ResponseModel <bool?> .GetReponseErrors(entityValidate.Errors));
                }
            }
            catch (Exception)
            {
                throw;
            }
        }