Пример #1
0
        public ResponseBase <bool> UpdateCustomer(CustomerContract data)
        {
            var response = new ResponseBase <bool>()
            {
                Data = false
            };

            try
            {
                using (var context = new EF_DataBaseEntities())
                {
                    context.USP_CUSTOMER_UPDATE(data.Id, data.Name, data.Address, data.BirthDate.ToDateTime(), data.DocumentId, data.DocumentType, data.CityId);
                    context.SaveChanges();

                    response.Code    = StatusCode.Ok;
                    response.Data    = true;
                    response.Message = $"Usuario con ID {data.Id} fue actualizado correctamente";
                }
            }
            catch (Exception ex)
            {
                response.Code    = StatusCode.InternalError;
                response.Message = ex.Message;
                response.Message = $"Ups! no se pudo actualizar el usuario {data.Id}: {ex.Message}";
            }

            return(response);
        }
Пример #2
0
        public ResponseBase <bool> DeleteCustomer(long id)
        {
            var response = new ResponseBase <bool>()
            {
                Data = false
            };

            try
            {
                using (var context = new EF_DataBaseEntities())
                {
                    context.USP_CUSTOMER_DELETE(id);
                    context.SaveChanges();

                    response.Code    = StatusCode.Ok;
                    response.Data    = true;
                    response.Message = $"Usuario con ID {id} fue eliminado correctamente";
                }
            }
            catch (Exception ex)
            {
                response.Code    = StatusCode.InternalError;
                response.Message = ex.Message;
                response.Message = $"Ups! no se pudo eliminar el usuario {id}: {ex.Message}";
            }

            return(response);
        }
Пример #3
0
        public ResponseBase <long> CreateCustomer(CustomerContract data)
        {
            var response = new ResponseBase <long>();

            try
            {
                using (var context = new EF_DataBaseEntities())
                {
                    var id = new ObjectParameter("id", typeof(long));
                    context.USP_CUSTOMER_CREATE(data.Name, data.Address, data.BirthDate.ToDateTime(), data.DocumentId, data.DocumentType, data.CityId, id);
                    context.SaveChanges();

                    response.Code    = StatusCode.Ok;
                    response.Data    = long.Parse(id.Value.ToString());
                    response.Message = $"Usuario creado correctamente con ID {response.Data}";
                }
            }
            catch (Exception ex)
            {
                response.Code    = StatusCode.InternalError;
                response.Message = $"Ups! no se pudo crear el usuario: {ex.Message}";
            }

            return(response);
        }